User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdlib.h:mblen

mblen

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

Description

Determines how many bytes are used for a character.

  <setlocale.h> is for this example nessesary 

mblen C Sourcecode Example 1

/* 
 * mblen example code
 * http://code-reference.com/c/stdlib.h/mblen 
 */
 
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
#include <stdlib.h>
#include <locale.h> /* for setlocale */
 
int main(void)
{
   setlocale(LC_ALL,""); 
   char *mbstring = "Ü";
   printf("character %s has a length of %d and MB_CUR_MAX is %i\n", mbstring, mblen(mbstring, 4), MB_CUR_MAX);
 
return 0;
}

output example 1 of mblen

  user@host:~/code-reference.com#  ./mblen6 
  character Ü has a length of 2 and MB_CUR_MAX is 6
  <setlocale.h> and <wchar.h> is for this example nessesary  

mblen C Sourcecode Example 2

/* 
 * mblen example code
 * http://code-reference.com/c/stdlib.h/mblen 
 */
 
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
#include <stdlib.h>
 
#include <wchar.h>  /* for wchar_t*/
#include <locale.h> /* for setlocale */
 
int main(void)
{
   setlocale(LC_ALL,"");   
   char  string[] = "?";
   int      length;
   wchar_t  widechar;
 
   length = mblen(string, MB_CUR_MAX);
   mbtowc(&widechar, string, length);
   printf("wide character %lc has a length of %d.\n", widechar, length);
 
   return 0;
 
}

output example 2 of mblen

  user@host:~/code-reference.com#  ./mblen3 
  wide character ? has a length of 3.
advertising
c/stdlib.h/mblen.txt · Last modified: 2013/01/22 22:02 (external edit)

Impressum Datenschutz