C 庫函數 - mbtowc()
描述
C 庫函數 int mbtowc(whcar_t *pwc, const char *str, size_t n) 把一個多位元組序列轉換為一個寬字元。
聲明
下麵是 mbtowc() 函數的聲明。
int mbtowc(whcar_t *pwc, const char *str, size_t n)
參數
- pwc -- 指向類型為 wchar_t 對象的指針。
- str -- 指向多位元組字元的第一個位元組的指針。
- n -- 要被檢查的最大字節數。
返回值
- 如果 str 不為 NULL,mbtowc() 函數返回 str 開始消耗的位元組數,如果指向一個空位元組,則返回 0,如果操作失敗,則返回 -1。
- 如果 str 為 NULL,如果編碼具有移位狀態,則 mbtowc() 函數返回非零,如果編碼是無狀態的,則返回零。
實例
下麵的實例演示了 mbtowc() 函數的用法。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *str = "這裏是 xuhuhu.com";
wchar_t mb[100];
int len;
len = mblen(NULL, MB_CUR_MAX);
mbtowc(mb, str, len*strlen(str) );
wprintf(L"%ls \n", mb );
return(0);
}
讓我們編譯並運行上面的程式,這將產生以下結果,因為它要以多位元組形式輸出結果,這是一種二進位輸出。
???

C 標準庫 - <stdlib.h>