This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/mbsrto_s.c

44 lines
1,006 B
C
Raw Normal View History

#define __STDC_WANT_LIB_EXT1__ 1
#include <stdio.h>
#include <wchar.h>
#include <mbctype.h>
#include <errno.h>
const char chars[] = {
' ',
'.',
'1',
'A',
0x81,0x40, /* double-byte space */
0x82,0x60, /* double-byte A */
0x82,0xA6, /* double-byte Hiragana */
0x83,0x42, /* double-byte Katakana */
0xA1, /* single-byte Katakana punctuation */
0xA6, /* single-byte Katakana alphabetic */
0xDF, /* single-byte Katakana alphabetic */
0xE0,0xA1, /* double-byte Kanji */
0x00
};
int main()
{
int i;
size_t retval;
const char *src;
wchar_t wc[50];
mbstate_t pstate;
errno_t rc;
_setmbcp( 932 );
src = chars;
rc = mbsrtowcs_s( &retval, wc, 50, &src, sizeof(chars), &pstate );
if( rc != 0 ) {
printf( "Error in multibyte character string\n" );
} else {
for( i = 0; i < retval; i++ ) {
printf( "%#6.4x\n", wc[i] );
}
}
return( 0 );
}