C语言isascii()函数:检测字符是否为ASCII字符

头文件:#include <ctype.h>

isascii() 用来检测一个字符是否是ASCII码字符,其原型为:
    int isascii(int c);

【参数】c 为需要检测的字符。

【返回值】若 c 为ASCII码(在0 到127 之间),返回非 0 值,否则返回 0。

注意,此为宏定义,非真正函数。

【实例】判断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);
}
输出结果:
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