c语言怎么判断字符是否为ASCII码字符



c语言isascii()函数是怎么判断字符是否为ASCII码字符?使用的方法是什么?头文件:#include <ctype.h>

c语言定义isascii()函数:int isascii(int c);

函数介绍:检查参数c是否为ASCII 码字符,也就是判断c 的范围是否在0 到127 之间。

isascii()函数返回值:若参数c 为ASCII 码字符,则返回true,否则返回NULL(0)。

函数使用注意事项:此为宏定义,非真正函数。

isascii()函数使用实例:判断int i 是否具有对应的ASCII 码字符。

#include <ctype.h>
main(){
    int i;
    for(i = 125; i < 130; i++)
    if(isascii(i))
        printf("%d is an ascii character:%c\n", i, i);
    else
        printf("%d is not an ascii character\n", i);
}

isascii()函数实例执行结果:
125 is an ascii character:}
126 is an ascii character:~
127 is an ascii character:
128 is not an ascii character
129 is not an ascii character