Computer >> Computer tutorials >  >> Programming >> C programming

isgraph() C library function


The function isgraph() is used to check that the passed character has a graphical representation or not. It is declared in “ctype.h” header file.

Here is the syntax of isgraph() in C language,

int isgraph(int char);

Here is an example of isgraph() in C language,

Example

#include<stdio.h>
#include<ctype.h>
int main() {
   int a = '\n';
   int b = '8';
   int c = 's';
   if(isgraph(a))
   printf("The character has graphical representation\n");
   else
   printf("The character isn’t having graphical representation\n");
   if(isgraph(b))
   printf("The character has graphical representation\n");
   else
   printf("The character isn’t having graphical representation");
   if(isgraph(c))
   printf("The character has graphical representation\n");
   else
   printf("The character isn’t having graphical representation");
   return 0;
}

Output

The character isn’t having graphical representation
The character has graphical representation
The character has graphical representation

In the above program, Three variables are declared and initialized. These variables are checked that they have graphical representation or not using isgraph() function.

if(isgraph(a))
printf("The character has graphical representation\n");
else
printf("The character isn’t having graphical representation\n");