Format
#include <stdlib.h>
int wctomb(char *string, wchar_t character);
Language Level: ANSI
Threadsafe: No. Use wcrtomb() instead.
Locale Sensitive: The behavior of this function might be affected by the LC_CTYPE category of the current locale. The behavior might also be affected by the LC_UNI_CTYPE category of the current locale if LOCALETYPE(*LOCALEUCS2) or LOCALETYPE(*LOCALEUTF) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.
Wide Character Function: See Wide Characters for more information.
Description
The wctomb() function converts the wchar_t value of character into a multibyte array pointed to by string. If the value of character is 0, the function is left in the initial shift state. At most, the wctomb() function stores MB_CUR_MAX characters in string.
The conversion of the wide character is the same as described in wcstombs(). See this function for a Unicode example.
Return Value
The wctomb() function returns the length in bytes of the multibyte character. The value -1 is returned if character is not a valid multibyte character. If string is a NULL pointer, the wctomb() function returns nonzero if shift-dependent encoding is used, or 0 otherwise.
If a conversion error occurs, errno may be set to ECONVERT.
Example that uses wctomb()
This example converts the wide character c to a multibyte character.
#include <stdio.h>
#include <stdlib.h>
#include <wchar.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 );
}
/**************** Output should be similar to: ******************
The number of bytes that comprise the multibyte character is 1
And the converted string is "c"
*/
Related Information