Convert a wide character to the corresponding multibyte character.
#include <stdlib.h>
int wctomb( char *mbchar, wchar_t wchar );
int __far _fwctomb( char __far *mbchar, wchar_t wchar );
mbchar | The address of a multibyte character | |
wchar | A wide character |
The wctomb function converts its wchar argument to the corresponding multibyte character and stores the result at mbchar.
The _fwctomb function is a model-independent (large-model) form of the wctomb function. It can be called from any point in any program.
If either wctomb or _fwctomb converts the wide character to a multibyte character, it returns the number of bytes—which is never greater than MB_CUR_MAX—in the wide character. If wchar is the wide-character null character (L'\0'), wctomb returns 0. If the conversion is not possible in the current locale, wctomb returns –1.
wctomb
Standards:ANSI
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:DOS32X
_fwctomb
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
mblen, mbstowcs, mbtowc, wcstombs, MB_CUR_MAX, MB_LEN_MAX
/* WCTOMB.CPP illustrates the behavior of the wctomb function */
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
int i;
wchar_t wc = L'a';
char *pmbnull = NULL;
char *pmb = (char *)malloc( sizeof( char ) );
printf( "Convert a wide character:\n" );
i = wctomb( pmb, wc );
printf( "\tCharacters converted: %u\n", i );
printf( "\tMultibyte character: %.1s\n\n", pmb );
printf( "Attempt to convert when target is NULL:\n" );
i = wctomb( pmbnull, wc );
printf( "\tCharacters converted: %u\n", i );
printf( "\tMultibyte character: %.1s\n", pmbnull );
}
Convert a wide character:
Characters converted: 1
Multibyte character: a
Attempt to convert when target is NULL:
Characters converted: 0
Multibyte character: (null)