#include <wchar.h>
|
size_t
mbrtowc (wchar_t * restrict dst, const char * restrict src, size_t n, mbstate_t * restrict ps); |
0 | The next n or fewer bytes represent the null wide character (L’\0’). |
>0 | The next n or fewer bytes represent a valid character, mbrtowc returns the number of bytes used to complete the multibyte character. |
(size_t-2) | |
The next n contribute to, but do not complete, a valid multibyte character sequence, and all n bytes have been processed. | |
(size_t-1) | |
An encoding error has occurred. The next n or fewer bytes do not contribute to a valid multibyte character. | |
If s is NULL, mbrtowc behaves as if pwc was NULL, s was an empty string ("") and n was 1.
The mbstate_t argument, ps, is used to keep track of the shift state. If it is NULL, mbrtowc uses an internal, static mbstate_t object, which is initialized to the initial conversion state at program startup.
The behavior of the mbrtowc is affected by LC_CTYPE category of the current locale.
#include <stdio.h> #include <stdlib.h> #include <wchar.h> /* Illustrates how to use mbrtowc API */ size_t example_mbrtowc() { size_t len; wchar_t wc[100]; char *s = ’a’; size_t n = 1; mbstate_t ps; /* converting multibyte sequence to a wide-char sequence */ len = mbrtowc(wc,(const char *) s, n, &ps); /* checking for error value */ if(len < 0) { wprintf(L"mbrtowc returned error!!\n"); } /* returning no of bytes consumed */ return (len); }
[EILSEQ] | |
An invalid multibyte sequence was detected. | |
[EINVAL] | |
The conversion state is invalid. | |
© 2005-2007 Nokia |