C Library Function isgraph( )

In this tutorial, you will learn about C library function isgraph() which is a character handling function used to check whether the argument supplied is a printing character or not.

This function returns a true value if its argument is a printing character other than space and zero (0) otherwise.

C Library Function isgraph( )

As discussed earlier, we have to include ctype.h header file for using isgraph( ) standard character library function.

#include <ctype.h>

C Library Function isgraph( ): Function prototype


int isgraph( int ch);

This function checks whether its argument is a printing character or not.

It returns a true value if its argument ch is a printing character other than a space and zero (o) otherwise.

Note: The only difference between isgraph and isprint is that space is not included in isgraph.

Demonstration of isgraph( )

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

int main()
{
 printf("Demonstration of isgraph():\n");
 printf("\n%s%s", isgraph('W') ? "W is a " : "W is not a ", "printing character");
 printf("\n%s%s%s", "Space", isgraph(' ') ? " is a " : " is not a ", "printing character");

 return 0;
}

[adsense1]

Output

Demonstration of isgraph():

W is a printing character
Space is not a printing character

Explanation
In the above example, standard character library function isgraph determines whether its argument is a printing character other than space.

Conditional operator ?: does the selection between two strings "is a" and "is not a".

This can be simply done with the help of if...else statements.


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

int main()
{
   printf("Demonstration of isgraph( ):\n");

   if( isgraph('W') == 0)
     printf("\nW is not printing character");
   else
     printf("\nW is a printing character");

   if( isgraph(' ') == 0)
     printf("\nSpace is not printing character");
   else
     printf("\nSpace is a printing character");

 return 0;
}

Output

Demonstration of isgraph():

W is a printing character
Space is not a printing character

Explanation

In this example, we have used if...else statements instead of a conditional operator.
Here, if...else statement does the selection between two strings.