1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
/* wcsrtombs example */
#include <stdio.h>
#include <wchar.h>
int main() {
const wchar_t str[] = L"wcstombs example";
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;
}
|