Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/m/mblen.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/m/mblen.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/m/mblen.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/m/mblen.html on line 8
Count the bytes in a multibyte character
#include <stdlib.h>
int mblen( const char * s,
size_t n );
- s
- NULL (see below), or a pointer to a multibyte character.
- n
- The maximum number of bytes that you want to count.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The mblen() function counts the number of bytes in the
multibyte character pointed to by s, to a maximum of n bytes.
The
mbrlen()
function is a restartable version of mblen().
- If s is NULL, mblen() determines whether or not the character encoding is state-dependent:
- 0
- The mblen() function uses locale-specific multibyte character encoding
that's not state-dependent.
- ≠ 0
- Character is state-dependent.
- If s isn't NULL:
- 0
- s points to the null character.
- -1
- The next n bytes don't form a valid multibyte character.
- > 0
- The number of bytes that comprise the multibyte character (if the
next n or fewer bytes form a valid multibyte character).
#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)
ANSI,
POSIX 1003.1
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Yes |
Thread |
Yes |
mbrlen(),
mbrtowc(),
mbsinit(),
mbsrtowcs(),
mbstowcs(),
mbtowc()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/m/mblen.html on line 201
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/m/mblen.html on line 201