determine the number of bytes comprising a multibyte character
#include <stdlib.h> or #include <mbstring.h> int mblen( const char *s, size_t n );
The mblen() function determines the number of bytes comprising the multibyte character pointed to by s. At most n bytes of the array pointed to by s will be examined.
If s is a NULL pointer, mblen() returns zero if multibyte character encodings aren't state-dependent, and nonzero otherwise. If s isn't a NULL pointer, mblen() returns:
#include <stdio.h> #include <stdlib.h> void main() { int len; char *mbs = "string"; printf( "Character encodings do %shave " "state-dependent \nencoding.\n", ( mblen( NULL, 0 ) ) ? "" : "not " ); len = mblen( "string", 6 ); if( len != -1 ) { mbs[len] = '\0'; printf( "Multibyte char %s(%d)\n", mbs, len ); } }
produces the output:
Character encodings do not have state-dependent encoding. Multibyte char s(1)
ANSI
Safety: | |
---|---|
Interrupt handler | Yes |
Signal handler | Yes |
Thread | Yes |
mbtowc(), mbstowcs(), wctomb(), wcstombs()