Преобразовать многобайтовый символ в широкий символ
#include <stdlib.h>int mbtowc( wchar_t *pwc,const char *s,size_t n );
wchar_t
object where the function can store the wide character.NULL
, or a pointer to the multibyte character that you want to convert.libc
The mbtowc() function converts a single multibyte character pointed to by s into a wide-character code pointed to by pwc, to a maximum of n bytes. The function stops early if it encounters the NULL
character.
This function is affected by LC_TYPE
.
The mbrtowc() function is a restartable version of mbtowc().
NULL:
NULL:
NUL
character. MB_CUR_MAX
(if the next n or fewer bytes form a valid multibyte character).
#include <stdio.h>#include <stdlib.h>int main( void ){char *wc = "string";wchar_t wbuffer[10];int i, len;printf( "State-dependent encoding? " );if ( mbtowc( wbuffer, NULL, 0 ) ){printf( "Yes\n" );} else {printf( "No\n" );}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" );return (EXIT_SUCCESS);}
Код генерирует следующий вывод:
$ ./a.out State-dependent encoding? No string(1) /0073
ANSI, POSIX 1003.1
btowc(), errno, mblen(), mbrlen(), mbrtowc(), mbsinit(), mbsrtowcs(), mbstowcs()
Предыдущий раздел: Описание API системной библиотеки