Format
#include <stdlib.h> int wctomb(char *string, wchar_t wc);
Language Level: ANSI, XPG4
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.
Return Value
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. Because this product does not support state-dependent encoding, wctomb always returns 0 when string is NULL.
Example
This example calls wctomb to convert the wide character
c to a multibyte character.
#include <stdio.h> #include <stdlib.h> #include <wcstr.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"
****************************************************************************/
}
![]()
mbtowc -- Convert Multibyte Character to
Wide Character
wcrtomb -- Convert Wide Character to
Multibyte Character
wcslen -- Calculate Length of
Wide-Character String
wcsrtombs -- Convert Wide-Character
String to Multibyte String
wcstombs -- Convert Wide-Character
String to Multibyte String
wctob -- Convert Wide Character to Byte
<stdlib.h>
<wcstr.h>