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

isgraph函数


概要:
#include <ctype.h>
int isgraph(int c);

描述:

该函数用于检查字符是否为打印字符(空格符除外)。

打印字符是在显示设备上占一个打印位置的字符;所有字母和数字都是打印字符。

该函数行为会受当前语言环境影响。对于ASCII字符集,打印字符(空格符除外)为ASCII值大于0x20的字符(0x7f(DEL)除外)。


参数:
int c

参数c为一个int类型整数,其值可用unsigned char类型表示或者等于宏EOF。如果参数c是其它值,函数行为是未定义的。


返回值:

如果参数c是打印字符(空格符除外),函数返回非0值(即true);反之,如果参数c不是打印字符(空格符除外),函数返回0(即false)。


范例:
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
/*函数isgraph范例*/

#include <ctype.h>
#include <stdio.h>

int main(void)
{
    int i = 0;
    int count = 0;    //计数器,统计打印字符(空格符除外)的数量。
    const char str[] = "I am a slow walker, but I never walk backwards.";

    while(str[i])
    {
        if(isgraph(str[i]))
            ++count;
        ++i;
    }

    printf("There are %d printing characters except space in the sentence.", count);

    return 0;
}

输出:

There are 38 printing characters except space in the sentence.


相关内容:
isprint 检查字符是否为打印字符(包括空格符' ')的函数。
iscntrl 检查字符是否为控制字符的函数。
ispunct 检查字符是否为标点符号的函数。