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 multibyte string to wide character string

&pagelevel(4)&pagelevel

Definition

#include <stdlib.h>

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

mbstowcs converts a sequence of multibyte characters in the string pointed to by s to the
corresponding wide characters (of type wchar_t) and writes a maximum of n wide
characters to the area specified by pwcs.
Conversion continues until either n values have been converted or the null value is encountered
(the null value is converted to the wchar_t value 0).

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

If an invalid character is encountered, mbstowcs returns the value (size_t)-1.

The wide characters stored by mbstowcs in the pwcs area correspond to the values of the
individual bytes in string s.

Return val.

Number of wide characters 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 resulting 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. Multibyte
characters and wide characters always have a length of 1 byte.
The shift state of the multibyte character is ignored.

See also

mblen, mbtowc, wcstombs, wctomb