mblen -- Determine Length of Multibyte Character

Format

#include <stdlib.h>
int mblen(const char *string, size_t n);

Language Level: ANSI, XPG4
mblen determines the length in bytes of the multibyte character pointed to by string. A maximum of n bytes is examined.

The behavior of mblen is affected by the LC_CTYPE category of the current locale.

Return Value
If string is NULL, mblen returns 0.

Note: On platforms that support shift states, mblen can also return a nonzero value to indicate that the multibyte encoding is state-dependent.

For OS/2 and Windows, because IBM C and C++ Compilers does not support state-dependent encoding, mblen always returns 0 when string is NULL.

If string is not NULL, mblen returns:

Example
This example uses mblen and mbtowc to convert a multibyte character into a single wide character.

#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <locale.h>
#define LOCNAME "ja_jp.ibm-932"
int main(void)
{
   char     mb_string[] = "\x81\x41\x81\xc2" "b";
   int      length;
   wchar_t  widechar;
   if (NULL == setlocale(LC_ALL, LOCNAME)) {
      printf("Locale \"%s\" could not be loaded\n", LOCNAME);
      exit(1);
   }
   length = mblen(mb_string, MB_CUR_MAX);
   mbtowc(&widechar, mb_string, length);
   printf("The wide character %lc has length of %d.\n", widechar, length);
   return 0;
   /***********************************************************************
      The output should be similar to:
      The first character is encoded in 2 bytes.
   ***********************************************************************/
}


mbrlen -- Calculate Length of Multibyte Character
mbrtowc -- Convert Multibyte Character to Wide Character
mbsrtowcs -- Convert Multibyte String to Wide-Character String
mbstowcs -- Convert Multibyte String to Wide-Character String
mbtowc -- Convert Multibyte Character to Wide Character
setlocale -- Set Locale
strlen -- Determine String Length
wcrtomb -- Convert Wide Character to Multibyte Character
wcslen -- Calculate Length of Wide-Character String
wcsrtombs -- Convert Wide-Character String to Multibyte String
wctomb -- Convert Wide Character to Mulitbyte Character
<locale.h>
<stdlib.h>