convert multibyte characters to wide characters
#include <stdlib.h>
size_t mbstowcs( wchar_t *pwcs,
const char *s,
size_t n );
The mbstowcs() function converts a sequence of multibyte characters pointed to by s into their corresponding wide-character codes, and stores not more than n codes into the array pointed to by pwcs. The mbstowcs() function doesn't convert any multibyte characters beyond the null character. At most n elements of the array pointed to by pwcs will be modified.
If an invalid multibyte character is encountered, the mbstowcs() function returns (size_t)-1. Otherwise, the mbstowcs() function returns the number of array elements modified, not including the terminating zero code, if present.
#include <stdio.h>
#include <stdlib.h>
void main()
{
char *wc = "string";
wchar_t wbuffer[50];
int i, len;
len = mbstowcs( wbuffer, wc, 50 );
if( len != -1 ) {
wbuffer[len] = '\0';
printf( "%s(%d)\n", wc, len );
for( i = 0; i < len; i++ )
printf( "/%4.4x", wbuffer[i] );
printf( "\n" );
}
}
produces the output:
string(6) /0073/0074/0072/0069/006e/0067
ANSI
| Safety: | |
|---|---|
| Interrupt handler | Yes |
| Signal handler | Yes |
| Thread | Yes |
mblen(), mbtowc(), wctomb(), wcstombs()