C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
MBTOWC.CPP
                                             Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
/* MBTOWC.CPP illustrates the behavior of the mbtowc function
 */
 
#include <stdlib.h>
#include <stdio.h>
 
void main( void )
{
    int      i;
    char    *pmbc    = (char *)malloc( sizeof( char ) );
    wchar_t  wc      = L'a';
    wchar_t *pwcnull = NULL;
    wchar_t *pwc     = (wchar_t *)malloc( sizeof( wchar_t ) );
 
    printf( "Convert a wide character to multibyte character:\" );
    i = wctomb( pmbc, wc );
    printf( "\Characters converted: %u\", i );
    printf( "\Multibyte character: %x\\", pmbc );
 
    printf( "Convert multibyte character back to a wide character:\" );
    i = mbtowc( pwc, pmbc, MB_CUR_MAX );
    printf( "\Bytes converted: %u\", i );
    printf( "\Wide character: %x\\", pwc );
 
    printf( "Attempt to convert when target is NULL\" );
    printf( "  returns the length of the multibyte character:\" );
    i = mbtowc( pwcnull, pmbc, MB_CUR_MAX );
    printf( "\Length of multibyte character: %u\\", i );
 
    printf( "Attempt to convert a NULL pointer to a" );
    printf( " wide character:\" );
    pmbc = NULL;
    i = mbtowc( pwc, pmbc, MB_CUR_MAX );
    printf( "\Bytes converted: %u\", i );
}
                                    -♦-