isgraph() 函数用来检测一个字符是否是图形字符。
具有图形表示的字符是已知的图形字符。
isgraph()检查字符是否为图形字符。如果传递给isgraph()的参数是图形字符,则它将返回非零整数。如果不是,则返回0。
此函数在ctype.h 头文件中定义
int isgraph(int argument);
isgraph()函数采用单个参数并返回整数。
当将字符作为参数传递时,将传递字符的相应ASCII值,而不是传递该字符本身。
#include <stdio.h>
#include <ctype.h>
int main()
{
char c;
int result;
c = ' ';
result = isgraph(c);
printf("当%c被传递给isgraph()时 = %d\n", c, result);
c = '\n';
result = isgraph(c);
printf("当%c被传递给isgraph()时 = %d\n", c, result);
c = '9';
result = isgraph(c);
printf("当%c被传递给isgraph()时 = %d\n", c, result);
输出结果
当 被传递给isgraph()时 = 0
当
被传递给isgraph()时 = 0
当 9 被传递给isgraph()时 = 1
#include <stdio.h>
#include <ctype.h>
int main()
{
int i;
printf("C编程中的所有图形字符为: \n");
for (i=0;i<=127;++i)
{
if (isgraph(i)!=0)
printf("%c ",i);
}
return 0;
}
输出结果
C编程中的所有图形字符为:
! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~