const wchar_t **restrict src, rsize_t len,
Converts a sequence of wide characters from the array whose first element is pointed to by
*srcto its narrow multibyte representation that begins in the conversion state described by
*ps. If
dst
is not null, converted characters are stored in the successive elements of the char array pointed to by
dst
. No more than
len
bytes are written to the destination array. Each character is converted as if by a call to
wcrtomb. The conversion stops if:
len
. *src is set to point at the first unconverted wide character. This condition is not checked if dst
is a null pointer.Same as
(1), except that
retval
dst
, which may be dst[len] or dst[dstsz], whichever comes first (meaning up to len+1/dstsz+1 total bytes may be written). In this case, there may be no unshift sequence written before the terminating null.dstsz
src
and dst
overlap, the behavior is unspecified.retval
, ps
, src
, or *src is a null pointerdstsz
or len
is greater than RSIZE_MAX (unless dst
is null)dstsz
is not zero (unless dst
is null)len
is greater than dstsz
and the conversion does not encounter null or encoding error in the src
array by the time dstsz
is reached (unless dst
is null)wcsrtombs_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 <wchar.h>.
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 bytes (including any shift sequences, but excluding the terminating
'\0') written to the character array whose first element is pointed to by
dst
. If
dst
is a null pointer, returns the number of bytes that would have been written. On conversion error (if invalid wide character was encountered), returns
(size_t)-1, stores
EILSEQin
errno, and leaves
*psin unspecified state.
2)Returns zero on success (in which case the number of bytes 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
'\0'(unless
dst
is null or
dstmax
is zero or greater than
RSIZE_MAX)
[edit] Example#include <stdio.h> #include <locale.h> #include <string.h> #include <wchar.h> void print_wide(const wchar_t* wstr) { mbstate_t state; memset(&state, 0, sizeof state); size_t len = 1 + wcsrtombs(NULL, &wstr, 0, &state); char mbstr[len]; wcsrtombs(mbstr, &wstr, len, &state); printf("Multibyte string: %s\n", mbstr); printf("Length, including '\\0': %zu\n", len); } int main(void) { setlocale(LC_ALL, "en_US.utf8"); print_wide(L"z\u00df\u6c34\U0001f34c"); // or L"zÃæ°´ð" }
Output:
Multibyte string: zÃæ°´ð Length, including '\0': 11[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