The function mbstowcs () in C
Function size_t mbstowcs (* pwcs, const char * str, n) Converts the sequence of multi-byte char points pointed to by the parameter str to the array pointed to by pwcs .
Declare the function mbstowcs () in C
Below is the declaration for mbstowcs () in C:
size_t mbstowcs ( * pwcs , const char * str , n )
Parameters
pwcs : This is a pointer to an array of wchar_t elements.
str : This is a multi-byte char string to be interpreted.
n : This is the maximum number of wchar_t characters to be interpreted.
Returns the value
This function returns the number of characters interpreted, except for the ending null character. If you encounter an invalid multi-byte char, this function returns -1.
For example
The following C program illustrates the usage of mbstowcs () in C:
#include #include #include int main () { int len ; char * pmbnull = NULL ; char * pmb = ( char *) malloc ( MB_CUR_MAX ); wchar_t * pwc = L "Hi" ; wchar_t * pwcs = ( wchar_t *) malloc ( sizeof ( wchar_t )); printf ( "Chuyen doi thanh multibyte stringn" ); len = wcstombs ( pmb , pwc , MB_CUR_MAX ); printf ( "Cac ky tu duoc chuyen doi %dn" , len ); printf ( "Gia tri Hex cua multibyte char dau tien la: %#.4xn" , pmb ); printf ( "Chuyen doi nguoc lai thanh chuoi Wide-Charactern" ); len = mbstowcs ( pwcs , pmb , MB_CUR_MAX ); printf ( "Cac ky tu duoc chuyen doi %dn" , len ); printf ( "Gia tri Hex cua wide char dau tien la: %#.4xnn" , pwcs ); return ( 0 ); }
Compiling and running the above C program will result:
According to Tutorialspoint
Previous article: Function mblen () in C
Next lesson: The function mbtowc () in C
You should read it
- The function mblen () in C
- Call the function by value in C ++
- The wctomb () function in C
- Call the function by pointer in C ++
- Function in programming C
- The function mbtowc () in C
- The function wcstombs () in C
- The ord () function in Python
- Int () function in Python
- The function id () in Python
- Zip () function in Python
- The function dir () in Python
Maybe you are interested
Troubleshooting Chromebook Not Charging
How to use pictures as Excel chart columns
Bleach: Characters with the most changed appearances
Why do phones need wireless charging?
How to create names with special characters, add special characters to game names, game character names
How to prevent laptop battery from charging past 80% on Windows 11