Syntax
#include <stdlib.h> int wctomb(char *string, wchar_t wc);Description
wctomb converts the wide character wc into a multibyte character and stores it in the location pointed to by string. wctomb stores a maximum of MB_CUR_MAX characters in string.
The behavior of wctomb is affected by the LC_CTYPE category of the current locale.
wctomb returns the length in bytes of the multibyte character. If wc is not a valid multibyte character, wctomb returns -1.
If string is a NULL pointer, wctomb returns 0.
Note: On platforms that support shift states, wctomb can also return a nonzero value to indicate that the multibyte encoding is state dependent.
This example calls wctomb to convert the wide character c to a multibyte character.
#include <stdio.h> #include <stdlib.h> #define SIZE 40 int main(void) { static char buffer[SIZE]; wchar_t wch = L'c'; int length; length = wctomb(buffer, wch); printf("The number of bytes that comprise the multibyte ""character is %i\n", length); printf("And the converted string is \"%s\"\n", buffer); return 0; /**************************************************************************** The output should be: The number of bytes that comprise the multibyte character is 1 And the converted string is "c" ****************************************************************************/ }Related Information