convert a wide character to a multibyte character
#include <stdlib.h> int wctomb( char *s, wchar_t wc );
The wctomb() function determines the number of bytes required to represent the multibyte character corresponding to the wide character contained in wc. If s isn't a NULL pointer, the multibyte character representation is stored in the array pointed to by s. At most MB_CUR_MAX characters will be stored.
If s is a NULL pointer, the wctomb() function returns zero if multibyte character encodings aren't state-dependent, and nonzero otherwise.
If s isn't a NULL pointer, the wctomb() function returns:
#include <stdio.h> #include <stdlib.h> wchar_t wc = { 0x0073 }; char mbbuffer[2]; void main() { int len; printf( "Character encodings are %sstate-dependent.\n", ( wctomb( NULL, 0 ) ) ? "" : "not " ); len = wctomb( mbbuffer, wc ); mbbuffer[len] = '\0'; printf( "%s(%d)\n", mbbuffer, len ); }
produces the output:
Character encodings are not state-dependent. s(1)
ANSI
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
mblen(), mbstowcs(), mbtowc(), wcstombs()