Programming Reference/Librarys
Question & Answer
Q&A is closed
converts a multibyte character into a wide character.
<setlocale.h> <wchar.h> is for this example nessesary
/* * mbtowc example code * http://code-reference.com/c/stdlib.h/mbtowc */ #include <stdio.h> #include <stdlib.h> #include <wchar.h> /* wint_t*/ #include <locale.h> /* 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; }
mbtowc: 測試字符串