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.
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 );
}
                                    -♦-