当前位置: C语言 -- 标准库 -- <wchar.h> -- btowc

btowc函数


概要:
#include <wchar.h>
wint_t btowc(int c);

描述:

该函数将单字节字符转换为宽字符,可用于确定参数c在初始移位状态下是否构成一个有效的单字节字符。


参数:
int c

int类型整数,该值会内部转换为unsigned char类型。


返回值:

如果参数c等于EOF或者如果(unsigned char)c在初始移位状态时不能构成有效的单字节字符,函数返回WEOF;否则函数返回参数c对应的宽字符表示形式。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
/*函数btowc范例*/

#include <locale.h>
#include <stdio.h>
#include <wchar.h>

/*声明函数。*/
void func(int c);

int main(void)
{
    setlocale(LC_ALL, "");

    func(65);
    func(EOF);
    
    return 0;
}

/*定义函数。*/
void func(int c)
{
    if(btowc(c) == WEOF)
    {
        if(c == EOF)
            wprintf(L"参数值为EOF。\n");
        else
            wprintf(L"%d不能构成有效的单字节字符。\n", c);
    }
    else
    {
        wprintf(L"%d能够构成有效的单字节字符。\n", c);
    }
}


输出:

65能够构成有效的单字节字符。

参数值为EOF。


相关内容:
wctob 将宽字符转换为单字节字符的函数。