?
Ce document utilise Manuel du site Web PHP chinois Libérer
在頭文件<wchar.h>中定義 | ||
---|---|---|
wint_t btowc(int c); | (自C95以來) |
將單字節(jié)字符c(重新解釋為無符號(hào)字符)擴(kuò)展為寬字符等效字符。
大多數(shù)多字節(jié)字符編碼使用單字節(jié)代碼來表示ASCII字符集中的字符。 該函數(shù)可用于將這些字符轉(zhuǎn)換為wchar_t。
C | - | 單字節(jié)字符加寬 |
---|
若 c
為EOF
則返回WEOF
如果(無符號(hào)字符)c在初始轉(zhuǎn)換狀態(tài)下是有效的單字節(jié)字符,否則為WEOF。
#include <stdio.h>#include <wchar.h>#include <locale.h>#include <assert.h> void try_widen(unsigned char c){ wint_t w = btowc(c); if(w != WEOF) printf("The single-byte character %#x widens to %#x\n", c, w); else printf("The single-byte character %#x failed to widen\n", c);} int main(void){ char *loc = setlocale(LC_ALL, "lt_LT.iso88594"); assert(loc); printf("In Lithuanian ISO-8859-4 locale:\n"); try_widen('A'); try_widen('\xdf'); // German letter ? (U+00df) in ISO-8859-4 try_widen('\xf9'); // Lithuanian letter ? (U+0173) in ISO-8859-4 setlocale(LC_ALL, "lt_LT.utf8"); printf("In Lithuanian UTF-8 locale:\n"); try_widen('A'); try_widen('\xdf'); try_widen('\xf9');}
可能的輸出:
In Lithuanian ISO-8859-4 locale:The single-byte character 0x41 widens to 0x41The single-byte character 0xdf widens to 0xdfThe single-byte character 0xf9 widens to 0x173In Lithuanian UTF-8 locale:The single-byte character 0x41 widens to 0x41The single-byte character 0xdf failed to widen The single-byte character 0xf9 failed to widen
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.29.6.1.1 btowc函數(shù)(p:441)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.24.6.1.1 btowc函數(shù)(p:387)
wctob(C95) | 如果可能的話,將寬字符縮小為單字節(jié)窄字符(功能) |
---|