Determines how many bytes are used for a character.
<setlocale.h> is for this example nessesary
/* * 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; }
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 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; }
user@host:~/code-reference.com# ./mblen3 wide character ? has a length of 3.