[Previous] [Contents] [Next]

mblen()

Count the bytes in a multibyte character

Synopsis:

#include <stdlib.h>

int mblen( const char * s, 
           size_t n );

Library:

libc

Description:

The mblen() function counts the number of bytes in the multibyte character pointed to by s, to a maximum of n bytes.

Returns:

Examples:

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
    int len;
    char *mbs = "string";

    printf( "Character encodings do " );
    if( !mblen( NULL, 0 ) ) {
        printf( "not " );
    }
    printf( "have state-dependent \nencoding.\n" );

    len = mblen( "string", 6 );
    if( len != -1 ) {
        mbs[len] = '\0';
        printf( "Multibyte char '%s'(%d)\n", mbs, len );
    }
    
    return EXIT_SUCCESS;
}

This produces the output:

Character encodings do not have state-dependent 
encoding.
Multibyte char 's'(1)

Classification:

ANSI

Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

"Character manipulation functions" and "Wide-character functions" in the summary of functions chapter.


[Previous] [Contents] [Next]