1) Converts a multibyte character string from the array whose first element is pointed to by src
to its wide character representation. Converted characters are stored in the successive elements of the array pointed to by dst
. No more than len
wide characters are written to the destination array.
Each character is converted as if by a call to
mbtowc, except that the mbtowc conversion state is unaffected. The conversion stops if:
* The multibyte null character was converted and stored.
* An invalid (in the current C locale) multibyte character was encountered.
* The next wide character to be stored would exceed len
.
If src
and dst
overlap, the behavior is undefined
2) Same as (1), except that
* the function returns its result as an out-parameter retval
* if no null character was written to dst
after len
wide characters were written, then L'\0' is stored in dst[len]
, which means len+1 total wide characters are written
* if dst
is a null pointer, the number of wide characters that would be produced is stored in *retval
* the function clobbers the destination array from the terminating null and until dstsz
* If src
and dst
overlap, the behavior is unspecified.
* the following errors are detected at runtime and call the currently installed
constraint handlerfunction:
retval
or src
is a null pointerdstsz
or len
is greater than RSIZE_MAX/sizeof(wchar_t) (unless dst
is null)dstsz
is not zero (unless dst
is null)dstsz
multibyte characters in the src
array and len
is greater than dstsz
(unless dst
is null)mbstowcs_s
is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including <stdlib.h>.
In most implementations, mbstowcs
updates a global static object of type mbstate_t as it processes through the string, and cannot be called simultaneously by two threads, mbsrtowcs should be used in such cases.
POSIX specifies a common extension: if dst
is a null pointer, this function returns the number of wide characters that would be written to dst
, if converted. Similar behavior is standard for mbstowcs_s
and for mbsrtowcs.
dst
array) retval - pointer to a size_t object where the result will be stored [edit] Return value 1)
On success, returns the number of wide characters, excluding the terminating
L'\0', written to the destination array. On conversion error (if invalid multibyte character was encountered), returns
(size_t)-1.
2)zero on success (in which case the number of wide characters excluding terminating zero that were, or would be written to
dst
, is stored in
*retval), non-zero on error. In case of a runtime constraint violation, stores
(size_t)-1in
*retval(unless
retval
is null) and sets
dst[0]to
L'\0'(unless
dst
is null or
dstmax
is zero or greater than
RSIZE_MAX)
[edit] Example#include <stdio.h> #include <locale.h> #include <stdlib.h> #include <wchar.h> int main(void) { setlocale(LC_ALL, "en_US.utf8"); const char* mbstr = u8"z\u00df\u6c34\U0001F34C"; // or u8"zÃæ°´ð" wchar_t wstr[5]; mbstowcs(wstr, mbstr, 5); wprintf(L"MB string: %s\n", mbstr); wprintf(L"Wide string: %ls\n", wstr); }
Output:
MB string: zÃæ°´ð Wide string: zÃæ°´ð[edit] References
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4