{{keywords>wiki library source code example reference}} ===== mbtowc ===== #include int mbtowc(whcar_t *pwc, const char *str, size_t n); ===== Description ===== converts a multibyte character into a wide character. is for this example nessesary ===== mbtowc C Sourcecode Example ===== /* * mbtowc example code * http://code-reference.com/c/stdlib.h/mbtowc */ #include #include #include /* wint_t*/ #include /* setlocale*/ int main(void) { wchar_t wchar; char string[] = "mbtowc: 測試字符串"; int i=0, length=0; setlocale(LC_ALL,""); while ( ( length = mbtowc ( &wchar, &string[i], MB_CUR_MAX )) != 0) { printf( "%lc", (wint_t)wchar ); // printf("i=%i, length=%i\n",i, length); i += length; } printf("\n"); return 0; } ==== output of mbtowc example ==== mbtowc: 測試字符串