Convert a wide character into a multibyte character
#include <stdlib.h> int wctomb( char * s, wchar_t wc );
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The wctomb() function determines the number of bytes required to represent the multibyte character corresponding to the code contained in wc. If s isn't NULL, the multibyte character representation is stored in the array it points to. At most MB_CUR_MAX characters are stored.
#include <stdio.h> #include <stdlib.h> wchar_t wchar = { 0x0073 }; char mbbuffer[MB_CUR_MAX]; int main( void ) { int len; printf( "Character encodings do %shave " "state-dependent \nencoding.\n", ( wctomb( NULL, 0 ) ) ? "" : "not " ); len = wctomb( mbbuffer, wchar ); mbbuffer[len] = '\0'; printf( "%s(%d)\n", mbbuffer, len ); return EXIT_SUCCESS; }
This produces the output:
Character encodings do not have state-dependent encoding. s(1)
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
wcrtomb(), wcsrtombs(), wcstod(), wcstof(), wcstold(), wcstoimax(), wcstoumax(), wcstok(), wcstol(), wcstoll(), wcstombs(), wcstoul(), wcstoull(), wctob()