6.3.6 isgraph Function

Test for a graphical character.

Include

<ctype.h>

Prototype

int isgraph (int c);

Argument

c
The character to test.

Return Value

Returns a non-zero integer value if the character, c, is a graphical character; otherwise, returns zero.

Remarks

A character is considered to be a graphical character if it is any printable character except a space.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

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

int main(void)
{
  int ch;

  ch = '3';
  if (isgraph(ch))
    printf("3 is a graphical character\n");
  else
    printf("3 is NOT a graphical character\n");

  ch = '#';
  if (isgraph(ch))
    printf("# is a graphical character\n");
  else
    printf("# is NOT a graphical character\n");

  ch = ' ';
  if (isgraph(ch))
    printf("A space is a graphical character\n");
  else
    printf("A space is NOT a graphical character\n");
}

Example Output

3 is a graphical character
# is a graphical character
A space is NOT a graphical character