Format
#include <stdlib.h> int mbtowc(wchar_t *pwc, const char *string, size_t n);
Language Level: ANSI
Threadsafe: No. Use mbrtowc() instead.
Description
The mbtowc() function first determines the length of the multibyte character pointed to by string. It then converts the multibyte character to a wide character as described in mbstowcs. A maximum of n bytes are examined.
The behavior of this function is affected by the LC_CTYPE category of the current locale.
Return Value
If string is NULL, the mbtowc() function returns:
If string is not NULL, the mbtowc() function returns:
If a conversion error occurs, errno may be set to ECONVERT.
Example that uses mbtowc()
This example uses the mblen() and mbtowc() functions to convert a multibyte character into a single wide character.
#include <stdio.h> #include <stdlib.h> #define LOCNAME "qsys.lib/mylib.lib/ja_jp959.locale" /*Locale created from source JA_JP and CCSID 939 */ int length, temp; char string [] = "\x0e\x41\x71\x0f"; wchar_t arr[6]; int main(void) { /* initialize internal state variable */ temp = mbtowc(arr, NULL, 0); setlocale (LC_ALL, LOCNAME); /* Set string to point to a multibyte character. */ length = mblen(string, MB_CUR_MAX); temp = mbtowc(arr,string,length); arr[1] = L'\0'; printf("wide character string: %ls",arr); }
Related Information
(C) Copyright IBM Corporation 1992, 2006. All Rights Reserved.