©
本文檔使用 php中文網手册 發布
在头文件<wchar.h>中定义 | ||
---|---|---|
wint_t btowc(int c); | (自C95以来) |
将单字节字符c(重新解释为无符号字符)扩展为宽字符等效字符。
大多数多字节字符编码使用单字节代码来表示ASCII字符集中的字符。 该函数可用于将这些字符转换为wchar_t。
C | - | 单字节字符加宽 |
---|
若 c
为EOF
则返回WEOF
如果(无符号字符)c在初始转换状态下是有效的单字节字符,否则为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标准(ISO / IEC 9899:2011):
7.29.6.1.1 btowc函数(p:441)
C99标准(ISO / IEC 9899:1999):
7.24.6.1.1 btowc函数(p:387)
wctob(C95) | 如果可能的话,将宽字符缩小为单字节窄字符(功能) |
---|