Syntax
#include <stdlib.h> size_t mbstowcs(wchar_t *dest, const char *string, size_t len);Description
mbstowcs converts the multibyte character string pointed to by string into the wide-character array pointed to by dest. Depending on the encoding scheme used by the code set, the multibyte character string can contain any combination of single-byte or double-byte characters.
The conversion stops after len wide-characters in dest are filled or after a null byte is encountered. The terminating null character is converted to a wide character with the value 0; characters that follow it are not processed.
The behavior of mbstowcs is affected by the LC_CTYPE category of the current locale.
If successful, mbstowcs returns the number of characters converted and stored in dest, not counting the terminating null character. The string pointed to by dest ends with a null character unless mbstowcs returns the value len.
If it encounters an invalid multibyte character, mbstowcs returns (size_t)-1. If dest is a null pointer, the value of len is ignored and mbstowcs returns the number of wide characters required for the converted multibyte characters.
This example uses mbstowcs to convert the multibyte character mbs to a wide character string and store it in wcs.
#include <wchar.h> #include <stdio.h> #include <stdlib.h> #include <locale.h> #define SIZE 10 int main(void) { char mbs[] = "\x81\x41" "m" "\x81\x42"; wchar_t wcs[SIZE]; if (NULL == setlocale(LC_ALL, "ja_jp.ibm-932")) { printf("setlocale failed.\n"); exit(EXIT_FAILURE); } mbstowcs(wcs, mbs, SIZE); printf("The wide character string is %ls.\n", wcs); return 0; /**************************************************************************** The output should be similiar to : The wide character string is ₧Am₧B. ****************************************************************************/ }Related Information