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