C examples for stdlib.h:wcstombs
function
<cstdlib> <stdlib.h>
Convert wide-character string to multibyte string
size_t wcstombs (char* dest, const wchar_t* src, size_t max);
Parameter | Description |
---|---|
dest | an array of char long enough to store the resulting sequence, at most, max bytes. |
src | C wide string to be translated. |
max | Maximum number of bytes to be written to dest. |
On success, the number of bytes written to dest.
On error, -1 value is returned.
#include <stdio.h> #include <stdlib.h> int main() {/*from w w w. j av a2s.c om*/ const wchar_t str[] = L"wcstombs example this is a test"; 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; }