| Functions | |||||||||||||||||||||||||||||||||||||||||
| Wide/multibyte conversions | |||||||||||||||||||||||||||||||||||||||||
(C95) | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| Types | |||||||||||||||||||||||||||||||||||||||||
| Macros | |||||||||||||||||||||||||||||||||||||||||
Defined in header <stdlib.h> | ||
| (1) | ||
| (until C99) | ||
| (since C99) | ||
errno_t mbstowcs_s(size_t*restrict retval,wchar_t*restrict dst, rsize_t dstsz,constchar*restrict src, rsize_t len); | (2) | (since C11) |
src to its wide character representation. Converted characters are stored in the successive elements of the array pointed to bydst. No more thanlen wide characters are written to the destination array.len.src anddst overlap, the behavior is undefinedretvaldst afterlen wide characters were written, thenL'\0' is stored indst[len], which means len+1 total wide characters are writtendst is a null pointer, the number of wide characters that would be produced is stored in*retvaldstszsrc anddst overlap, the behavior is unspecified.retval orsrc is a null pointerdstsz orlen is greater thanRSIZE_MAX/sizeof(wchar_t) (unlessdst is null)dstsz is not zero (unlessdst is null)dstsz multibyte characters in thesrc array andlen is greater thandstsz (unlessdst 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 constant1 before including<stdlib.h>.Contents |
In most implementations,mbstowcs updates a global static object of typembstate_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: ifdst is a null pointer, this function returns the number of wide characters that would be written todst, if converted. Similar behavior is standard formbstowcs_s and formbsrtowcs.
| dst | - | pointer to wide character array where the wide string will be stored |
| src | - | pointer to the first element of a null-terminated multibyte string to convert |
| len | - | number of wide characters available in the array pointed to by dst |
| dstsz | - | max number of wide characters that will be written (size of thedst array) |
| retval | - | pointer to a size_t object where the result will be stored |
dst, is stored in*retval), non-zero on error. In case of a runtime constraint violation, stores(size_t)-1 in*retval (unlessretval is null) and setsdst[0] toL'\0' (unlessdst is null ordstmax is zero or greater thanRSIZE_MAX)Output:
MB string: zß水🍌Wide string: zß水🍌
(C95)(C11) | converts a narrow multibyte character string to wide string, given state (function)[edit] |
(C11) | converts a wide string to narrow multibyte character string (function)[edit] |
C++ documentation formbstowcs | |