mbstowcs function(Convert Multibyte String to Wide Character String) in C Language – example and detail

In the C Programming Language, the mbstowcs function converts a multibyte string (as pointed to by s) into a wide character string (as pointed to by pwcs) up to n codes in length.

Syntax

The syntax for the mbstowcs function in the C Language is:

size_t mbstowcs(wchar_t *pwcs, const char *s, size_t n);

Parameters or Arguments

pwcs

The array where the converted wide character string will be stored.

s

The multibyte string to convert into a wide character string.

n

The maximum number of codes to store in pwcs.

Note

The mbstowcs function will end the conversion if a null character is encountered at which point it is converted into a code with a value of zero.

Returns

The mbstowcs function returns the number of elements modified (not including the terminating code if applicable). The mbstowcs function will return -1 if it encountered an invalid multibyte character.

Required Header

In the C Language, the required header for the mbstowcs function is:

#include <stdlib.h>

Applies To

In the C Language, the mbstowcs function can be used in the following versions:

ANSI/ISO 9899-1990

Similar Functions

Other C functions that are similar to the mbstowcs function:

wcstombs function <stdlib.h>

See Also

Other C functions that are noteworthy when dealing with the mbstowcs function:

mblen function <stdlib.h>

mbtowc function <stdlib.h>

setlocale function <locale.h>

wctomb function <stdlib.h>