C Language and Libraries Help (clang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
MBSTOWCS.CPP
◄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 );
}
-♦-