function
<cstdlib>
wcstombssize_t wcstombs (char* dest, const wchar_t* src, size_t max);
Convert wide-character string to multibyte string
Translates wide characters from the sequence pointed by src to the multibyte equivalent sequence (which is stored at the array pointed by dest), up until either max bytes have been translated or until a wide characters translates into a null character.If max bytes are successfully translated, the resulting string stored in dest is not null-terminated.
The resulting multibyte sequence begins in the initial shift state (if any).
The behavior of this function depends on the LC_CTYPE category of the selected C locale.
char
elements long enough to contain the resulting sequence (at most, max bytes).
(size_t)-1
value is returned.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* wcstombs example */
#include <stdio.h> /* printf */
#include <stdlib.h> /* wcstombs, wchar_t(C) */
int main() {
const wchar_t str[] = L"wcstombs example";
char buffer[32];
int ret;
printf ("wchar_t string: %ls \n",str);
ret = wcstombs ( buffer, str, sizeof(buffer) );
if (ret==32) buffer[31]='\0';
if (ret) printf ("multibyte string: %s \n",buffer);
return 0;
}
wchar_t string: wcstombs example multibyte string: wcstombs example
If dest does not point to an array long enough to contain the translated sequence, or if src is either not null-terminated or does not contain enough wide characters to generate a sequence of max multibyte characters, it causes undefined behavior.
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