{{keywords>wiki library source code example reference}} ====== mblen ====== #include int mblen(const char *str, size_t n); ===== Description ===== Determines how many bytes are used for a character. is for this example nessesary ===== mblen C Sourcecode Example 1===== /* * mblen example code * http://code-reference.com/c/stdlib.h/mblen */ #include /* including standard library */ //#include /* uncomment this for Windows */ #include #include /* 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 and is for this example nessesary ===== mblen C Sourcecode Example 2===== /* * mblen example code * http://code-reference.com/c/stdlib.h/mblen */ #include /* including standard library */ //#include /* uncomment this for Windows */ #include #include /* for wchar_t*/ #include /* 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.