mbtowc()

Translates a multibyte character to a wchar_t type.

  #include <stdlib.h>
  
  int mbtowc(wchar_t *pwc, const char *s, size_t n);    
Parameter

pwc

The wide-character destination.

s

The string to convert.

n

The number of wide characters in pwc.

Remarks

If s is not a null pointer, the mbtowc() function examines at most n bytes starting with the byte pointed to by s to determine whether the next multibyte character is a complete and valid encoding of a Unicode character encoded as defined by the LC_CTYPE category of the current locale. If so, and pwc is not a null pointer, it converts the multibyte character, pointed to by s, to a character of type wchar_t, pointed to by pwc.

mbtowc() returns -1 if n is zero and s is not a null pointer or if s points to an incomplete or invalid multibyte encoding.

mbtowc() returns 0 if s is a null pointer or s points to a null character ( '\0').

mbtowc() returns the number of bytes of s required to form a complete and valid multibyte encoding of the Unicode character.

In no case will the value returned be greater than n or the value of the macro MB_CUR_MAX.