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.
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
Clouds on Neptune may be created by the Sun Decipher the mystery behind a photo of a 'human bone' object on NASA's Martian surface Why are microorganisms living 'so tough' on Earth but still hard to survive on Mars Police protect the planet: Light pay high, stable to doomsday, receive 200,000 USD / year from NASA Find strong evidence of life on Mars There are major changes in the atmosphere of Mars