The isgraph() function defined in the ctype.h header file. This function helps to check the specified character is a graphic character or not. The characters are said to be graphic characters they have a graphical representation which means all those characters except whitespace characters that can be printed.
int isgraph(int argument); #where argument will be a character
The isgraph() function takes a single parameter and is in the form of an integer and the return value should be an integer. When a character is passed it is converted into the integer value corresponding to its ASCII value.
Parameter | Description | Required / Optional |
---|---|---|
argument | The character to be checked | Required |
If the given character is a graphic character, isgraph() returns a non-zero integer else zero. When the graphic character is passed we will get a different non-zero integer.
Input | Return Value |
---|---|
Zero | If the parameter isn't a graphic character |
Non zero number | If the parameter is a graphic character |
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
int output;
ch = ' ';
output = isgraph(ch);
printf("If %c is passed to isgraph() = %d\n", ch, output);
ch = '\n';
output = isgraph(ch);
printf("If %c is passed to isgraph() = %d\n", ch, output);
ch = '4';
output = isgraph(ch);
printf("If %c is passed to isgraph() = %d\n", ch, output);
}
Output:
If is passed to isgraph() = 0 If If 4 is passed to isgraph() = 1
#include <stdio.h>
#include <ctype.h>
int main()
{
int k;
printf("All graphic characters are: \n");
for (k=0;k<=127;++k)
{
if (isgraph(k)!=0)
printf("%c ",k);
}
return 0;
}
Output:
All graphic characters are: ! " # $ % & ' ( ) * + , - . / 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 { | } ~