Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

mbstowcs - convert multi-byte string to wide-character string

&pagelevel(4)&pagelevel

Syntax

#include <stdlib.h>

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

Description mbstowcs() converts a sequence of multi-byte characters in the string s to the appropriate

wchar_t values and stores a maximum of n wchar_t values in the area pwcs. mbstowcs()
converts until either n values have been converted or a null value is encountered (null is
converted into the wchar_t value 0).

If pwcs is a null pointer, mbstowcs() returns the length required to convert the entire string,
regardless of the value n, but does not save any values.

If an invalid character is present in the string to be converted, mbstowcs() returns the value
(size_t)-1.

The wchar_t values (type long) which are stored by mbstowcs() in the pwcs area
correspond to the values of the individual bytes in the string s.

Return val.

Number of wchar_t values stored in pwcs (excluding the terminating null byte)

if pwcs is not a null pointer.
If the return value corresponds to the value n, the result area pwcs is not
terminated with the null byte.

Length required to convert the entire string,

if pwcs is a null pointer. No values are stored.

(size_t)-1

if an error occurs.

Notes

The behavior is undefined if memory areas overlap.

No characters consisting of multiple bytes are implemented in this version. Multi-byte
characters always have a length of 1 byte, and wchar_t values are always of type long.

See also

mblen(), mbtowc(), wcstombs(), wctomb(), stdlib.h.