6.19.40 wctomb Function
Converts a wide character to a multibyte character.
Include
<stdlib.h>
Prototype
int wctomb(char * s, wchar_t wc);
Arguments
s
- points to the multibyte character
wc
- the wide character to be converted
Return Value
Returns zero if s
points to a null character; otherwise, returns 1.
Remarks
The resulting multibyte character is stored at s
.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>
#define SIZE 40
int main(void)
{
static char buffer[SIZE];
wchar_t * wch = L"PIC®";
int length, idx;
setlocale(LC_CTYPE, "");
while(wch[idx]) {
length = wctomb(buffer, wch[idx]);
printf( "bytes in multibyte %lc is %i\n", wch[idx], length);
printf( "converted string \"%s\"\n", buffer);
idx++;
}
}
bytes in multibyte P is 1
converted string "P"
bytes in multibyte I is 1
converted string "I"
bytes in multibyte C is 1
converted string "C"
bytes in multibyte ® is 2
converted string "®"