isgraph C Library Function

isgraph function checks whether a character is graphic character or not. The characters with graphical representation are all those characters than can be printed, except the space character(” “) which is not a graph character.

Function prototype of isgraph

int isgraph(int c);

Function isgraph takes a character as input in form of an integer. When we pass a value of type char to isgraph function, corresponding ASCII value of that character is passed.

Return value of isgraph

If passed character has graphical representation as character, then isgraph function returns non-zero integer otherwise 0.

C program using isgraph function

The following program is to check whether a character has graphical representation or not.

isgraph C Library Function

#include <stdio.h>
#include <ctype.h>
#include <conio.h>
 
int main(){
    char string[] = "1 A";
    int index = 0;
     
    while(string[index] != '\0'){
        if(isgraph(string[index])){
            printf("'%c' is a graphical character\n", string[index]);
        } else {
            printf("'%c' is not a graphical character\n", string[index]);
        }
        index++;
    }
     
    getch();
    return 0;
}

Output

'1' is a graphical character
' ' is not a graphical character
'A' is a graphical character