convert a multibyte character to a wide character
#include <stdlib.h>
int mbtowc( wchar_t *pwc,
const char *s,
size_t n );
The mbtowc() function converts a single multibyte character pointed to by s into the wide character code that corresponds to it. The code for the null character is zero. If the multibyte character is valid and pwc isn't a NULL pointer, the code is stored in the object pointed to by pwc. At most n bytes of the array pointed to by s will be examined.
The mbtowc() function doesn't examine more than MB_CUR_MAX bytes.
If s is a NULL pointer, the mbtowc() function returns zero if multibyte character encodings aren't state-dependent, and nonzero otherwise. If s isn't a NULL pointer, the mbtowc() function returns:
#include <stdio.h>
#include <stdlib.h>
void main()
{
char *wc = "string";
wchar_t wbuffer[10];
int i, len;
printf( "Character encodings do %shave "
"state-dependent \nencoding.\n",
( mbtowc( wbuffer, NULL, 0 ) )
? "" : "not " );
len = mbtowc( wbuffer, wc, 2 );
wbuffer[len] = '\0';
printf( "%s(%d)\n", wc, len );
for( i = 0; i < len; i++ )
printf( "/%4.4x", wbuffer[i] );
printf( "\n" );
}
produces the output:
Character encodings do not have state-dependent encoding. string(1) /0073
ANSI
| Safety: | |
|---|---|
| Interrupt handler | Yes |
| Signal handler | Yes |
| Thread | Yes |
mblen(), mbstowcs(), wcstombs(), wctomb()