Skip to content
Related Articles

Related Articles

Improve Article

isgraph() C library function

  • Difficulty Level : Easy
  • Last Updated : 24 Oct, 2017
Geek Week

The C library function isgraph() checks whether a character is a graphic character or not.
Characters that have graphical representation are known are graphic characters. For example: ‘:’ ‘;’ ‘?’ ‘@’ etc.

Syntax –

#include <ctype.h>
int isgraph(int ch);

Return Value – function returns nonzero if ch is any printable character other than a space, else it returns 0.

For ASCII environments, printable characters are in the range of 0X21 through 0X7E.

Code –






// code to check graphical character
#include <stdio.h>
#include <ctype.h>
  
int main()
{
    char var1 = 'g';
    char var2 = ' ';
    char var3 = '1';
  
    if (isgraph(var1)) 
        printf("var1 = |%c| can be printed\n", var1);
    else 
        printf("var1 = |%c| can't be printed\n", var1);
  
    if (isgraph(var2)) 
        printf("var2 = |%c| can be printed\n", var2);
    else 
        printf("var2 = |%c| can't be printed\n", var2);
      
    if (isgraph(var3)) 
        printf("var3 = |%c| can be printed\n", var3);
    else 
        printf("var3 = |%c| can't be printed\n", var3);
  
    return (0);
}

Output –

var1 = |g| can be printed
var2 = | | can't be printed
var3 = |1| can be printed

Code –




// code to print all Graphical Characters
#include <stdio.h>
#include <ctype.h>
  
int main()
    int i;
    printf("In C programming All graphic "
            "characters are: \n");
  
    for (i = 0; i <= 127; ++i) 
        if (isgraph(i) != 0)
            printf("%c ", i);    
  
    return 0;
}

Output –

In C programming 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 { | } ~ 

This article is contributed by Shivani Ghughtyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Take a step-up from those “Hello World” programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.



My Personal Notes arrow_drop_up
Recommended Articles
Page :