C isgraph() Function Tutorial

In this section, we will learn what the isgraph() function is and how to use it in C.

isgraph() in C

Those types of printable characters that actually have a graphic representation are called graphic-characters.

For example, alphabet characters, numbers, etc.

The `isgraph ()` function is used to check whether a character has a graphic representation.

The prototype of the function exists in the `ctype.h` header file and we need to include this header file in order to use the ` isgraph ()` function.

isgraph() Function Syntax

Here’s the prototype of the ` isgraph ()` function:

int isgraph (int argument);

isgraph() Function Parameters

This function takes one argument and that is the character we want to check.

isgraph() Function Return Value

The return value of the function is:

  • 0: If the character was not a graphical character.
  • Positive value: if the character was in fact a graphical-character.

Example: using isgraph() function in C

#include <stdio.h>
#include <ctype.h>

int main() {

    char character = '\0';
    char c2 = '5';

    printf("The first character: %d \nThe second character: %d", isgraph (character), isgraph (c2));

    return  0;
}

Output:

The first character: 0

The second character: 2

The first character in this example is the newline character and so the result of calling the ` isgraph ` function is 0 value because `\0` is not a graphical-character. But the result of the second character is a positive value because the actual value of the character is `5` and it’s a graphical-character.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies