User Tools

Site Tools


c:stdlib.h:mblen

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdlib.h:mblen [2013/01/22 22:02] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +====== mblen ======
 +
 +<code c>
 +    #include <stdlib.h>
 +    int mblen(const char *str, size_t n); 
 + </code>
 +===== Description =====
 +Determines how many bytes are used for a character.
 +
 +
 +
 +    <setlocale.h> is for this example nessesary 
 +===== mblen C Sourcecode Example 1=====
 +<code c>
 +/* 
 + * 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;
 +}
 +</code>
 +
 +==== 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=====
 +<code c>
 +/* 
 + * 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;
 +
 +}
 +</code>
 +
 +==== 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