Syntax
#include <stdlib.h> int mbtowc(wchar_t *pwc, const char *string, size_t n);Description
mbtowc first determines the length of the multibyte character pointed to by string. It then converts the multibyte character to the corresponding wide character, and stores it in the location pointed to by pwc, if pwc is not a null pointer. mbtowc examines a maximum of n bytes from string.
If pwc is a null pointer, the multibyte character is not converted.
The behavior of mbtowc is affected by the LC_CTYPE category of the current locale.
If string is NULL, mbtowc returns 0. If string is not NULL, mbtowc returns:
This example uses mbtowc to convert the second multibyte character in mbs to a wide character.
#include <stdio.h>#include <stdlib.h> #include <wchar.h> #include <locale.h> int main(void) { char mb_string[] = "\x81\x41\x81\x42" "c" "\x00"; int length; wchar_t widechar; if (NULL == setlocale(LC_ALL, "ja_jp.ibm-932")) { printf("setlocale failed.\n"); exit(EXIT_FAILURE); } length = mblen(mb_string, MB_CUR_MAX); length = mbtowc(&widechar, mb_string + length, MB_CUR_MAX); printf("The wide character %lc has length of %d.\n", widechar, length); return 0; /**************************************************************************** The output should be similar to : The wide character žB has length of 2. ****************************************************************************/ }Related Information