Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

mbrtowc - Complete multibyte character and convert to wide character

&pagelevel(4)&pagelevel

Definition   

#include <wchar.h>

size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);

If s is not a null pointer, the mbrtowc function inspects at most n bytes beginning with the byte pointed to by *s to determine the number of bytes needed to complete the next multibyte character (including any shift sequences). If mbrtowc can complete the multibyte character, it determines the value of the corresponding wide character and then, if pwc is not a null pointer, stores that value in the object pointed to by *pwc.
If the corresponding wide character is the null wide character, the resulting state described is the initial conversion state.
If s is a null pointer, mbrtowc is equivalent to the call

mbrtowc(NULL, "", 1, ps)

In this case, the values of the parameters pwc and n are ignored.

Return val.

Depending on the value of the current conversion state, mbrtowc returns the first of the



following that applies:


0

if the next n or fewer bytes complete a valid multibyte character that corresponds to the null wide character.


Number of bytes needed to complete the multibyte character



if the next n or fewer bytes complete a valid multibyte character. The value stored is the wide character corresponding to that multibyte character.

 

(size_t)-2

if the next n bytes contribute to an incomplete (but potentially valid) multibyte character. No value is stored.


(size_t)-1

if an encoding error occurs, in which case the next n or fewer bytes do not contribute to a complete and valid multibyte character (no value is stored);
the value of the macro EILSEQ is stored in errno, and the conversion state is undefined.

Note

This version of the C runtime system only supports one-byte characters as wide character codes.

See also

mblen, mbtowc, wcstombs, wctomb