◄Up► ◄Contents► ◄Index► ◄Back► ─────Run-Time Library─────────────────────────────────────────────────────── /* MBSTOWCS.CPP illustrates the behavior of the mbstowcs function */ #include <stdlib.h> #include <stdio.h> void main( void ) { int i; char *pmbnull = NULL; char *pmbhello = (char *)malloc( MB_CUR_MAX ); wchar_t *pwchello = L"Hi"; wchar_t *pwc = (wchar_t *)malloc( sizeof( wchar_t )); printf( "Convert to multibyte string:\" ); i = wcstombs( pmbhello, pwchello, MB_CUR_MAX ); printf( "\Characters converted: %u\", i ); printf( "\Hex value of first" ); printf( " multibyte character: %#.4x\\", pmbhello ); printf( "Convert back to wide-character string:\" ); i = mbstowcs( pwc, pmbhello, MB_CUR_MAX ); printf( "\Characters converted: %u\", i ); printf( "\Hex value of first" ); printf( " wide character: %#.4x\\", pwc ); printf( "Attempt to convert a wide-character NULL pointer:\" ); i = mbstowcs( pwc, pmbnull, MB_CUR_MAX ); printf( "\Characters converted: %u\", i ); } -♦-