RAD Studio |  |

mblen

Header File

stdlib.h

Category

Memory and String Manipulation Routines

Prototype

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

Description

Determines the length of a multibyte character.

If s is not null, mblen determines the number of bytes in the multibyte character pointed to by s. The maximum number of bytes examined is specified by n.

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

Return Value

If s is null, mblen returns a nonzero value if multibyte characters have state-dependent encodings. Otherwise, mblen returns 0.

If s is not null, mblen returns 0 if s points to the null character, and -1 if the next n bytes do not comprise a valid multibyte character; the number of bytes that comprise a valid multibyte character.

Example

Copy Code

    #include <stdlib.h>
    #include <stdio.h>
    void main (void)
    {
      int i ;
      char *mulbc = (char *)malloc( sizeof( char) );
      wchar_t widec = L'a';
      printf (" convert a wide character to multibyte character:\n" );
      i = wctomb (mulbc, widec);
      printf( "\tCharacters converted: %u\n", i);
      printf( "\tMultibyte character: %x\n\n", mulbc);
      printf( " Find length--in byte-- of multibyte character:\n");
      i = mblen( mulbc, MB_CUR_MAX);
      printf("\tLength--in bytes--if multiple character: %u\n",i);
      printf("\tWide character: %x\n\n", mulbc);
      printf( " Attempt to find length of a Wide character Null:\n");
      widec = L'\0';
      wctomb(mulbc, widec);
      i = mblen( mulbc, MB_CUR_MAX);
      printf("\tLength--in bytes--if multiple character: %u\n",i);
      printf("\tWide character: %x\n\n", mulbc);
    }

Portability

POSIX | Win32 | ANSI C | ANSI C++
+ | + | + | +

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!