bTowc ()- 将单字节转换为宽字符
格式
#include <stdio.h>
#include <wchar.h>
wint_t btowc(int c);语言级别
ANSI
线程安全
是
语言环境敏感
此函数的行为可能受当前语言环境的 LC_CTYPE 类别影响。 如果在编译命令中指定了 LOCALETYPE (*LOCALEUCS2) 或 LOCALETYPE (*LOCALEUTF) ,那么此行为也可能受当前语言环境的 LC_UNI_CTYPE 类别影响。 当在编译命令上指定 LOCALETYPE (*CLD) 时,此功能不可用。 有关更多信息,请参阅 了解 CCSID 和语言环境。
宽字符函数
有关更多信息,请参阅 宽字符 。
描述
btowc() 函数将单字节值 c 转换为 c的宽字符表示。 如果 c 在初始移位状态下不构成有效 (1 字节) 多字节字符,那么 btowc() 函数将返回 WEOF。
返回值
如果 c 具有值 EOF ,或者如果 (无符号字符) c 在初始移位状态下不构成有效 (1 字节) 多字节字符,那么 btowc() 函数将返回 WEOF。 否则,它将返回该字符的宽字符表示。
如果发生转换错误,那么 errno 可能设置为 ECONVERT。
示例
此示例扫描各种类型的数据。
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <local.h>
#define UPPER_LIMIT 0xFF
int main(void)
{
int wc;
int ch;
if (NULL == setlocale(LC_ALL, "/QSYS.LIB/EN_US.LOCALE")) {
printf("Locale could not be loaded\n");
exit(1);
}
for (ch = 0; ch <= UPPER_LIMIT; ++ch) {
wc = btowc(ch);
if (wc==WEOF) {
printf("%#04x is not a one-byte multibyte character\n", ch);
} else {
printf("%#04x has wide character representation: %#06x\n", ch, wc);
}
}
wc = btowc(EOF);
if (wc==WEOF) {
printf("The character is EOF.\n", ch);
} else {
printf("EOF has wide character representation: %#06x\n", wc);
}
return 0;
}
/***********************************************************************
If the locale is bound to SBCS, the output should be similar to:
0000 has wide character representation: 000000
0x01 has wide character representation: 0x0001
...
0xfe has wide character representation: 0x00fe
0xff has wide character representation: 0x00ff
The character is EOF.
************************************************************************/