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