English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

Usage and example of C library function isgraph()

C Standard Library <ctype.h>

 The isgraph() function is used to detect whether a character is a graphic character.

Characters with graphic representation are known graphic characters.

isgraph() checks if a character is a graphic character. If the parameter passed to isgraph() is a graphic character, it will return a non-zero integer. If not, it returns 0.

This function is inctype.h  Defined in header file 

Function prototype of isgraph()

int isgraph(int argument);

The isgraph() function takes a single parameter and returns an integer.

When a character is passed as a parameter, the corresponding ASCII value of the character is passed, not the character itself.

Example1Check graphic characters

#include <stdio.h>
#include <ctype.h>
int main()
{
    char c;
    int result;
    c = ' ';
    result = isgraph(c);
    printf("When %c is passed to isgraph() = %d
", c, result);
    c = '\n';
    result = isgraph(c);
    printf("When %c is passed to isgraph() = %d
", c, result);
    c = '9';
    result = isgraph(c);
    printf("When %c is passed to isgraph() = %d
", c, result);

Output result

when          passed to isgraph() = 0
when 
 when passed to isgraph() = 0
when 9 when passed to isgraph() = 1

Example #2Print all graphic characters

#include <stdio.h>
#include <ctype.h>
int main()
{
    int i;
    printf("All graphic characters in C programming are: 
");
    for (i = 0; i <=127;++i)
    {
        if (isgraph(i) != 0)
            printf("%c ", i);
    }
    return 0;
}

Output result

All graphic characters in C programming 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 { | } ~

C Standard Library <ctype.h>