C examples for wchar.h:wcsrtombs
function
<cwchar> <wchar.h>
Convert wide-character string to multibyte string
size_t wcsrtombs (char* dest, const wchar_t** src, size_t max, mbstate_t* ps);
Parameter | Description |
---|---|
dest | a C string of max bytes. |
src | C wide string to be translated |
max | Maximum number of bytes characters to save to dest. |
ps | a conversion state. |
The number of bytes written to dest.
On error, -1 is returned.
#include <stdio.h> #include <wchar.h> int main() {/*from w w w . j ava2 s.c o m*/ const wchar_t str[] = L"this is a test test"; const wchar_t * p; mbstate_t mbs; char buffer[32]; int ret; mbrlen (NULL,0,&mbs); /* initialize mbs */ printf ("wchar_t string: %ls \n",str); p = str; ret = wcsrtombs ( buffer, &p, sizeof(buffer), &mbs ); if (ret==32) buffer[31]='\0'; if (ret) printf ("multibyte string: %s \n",buffer); return 0; }