isprint Function

Test for a printable character (includes a space).

Include

<ctype.h>

Prototype

int isprint(int c);

Argument

c
The character to test.

Return Value

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

Remarks

A character is considered to be a printable character if its ASCII value is in the range 0x20 to 0x7e inclusive.

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 = '&';
  if (isprint(ch))
    printf("& is a printable character\n");
  else
    printf("& is NOT a printable character\n");

  ch = '\t';
  if (isprint(ch))
    printf("A tab is a printable character\n");
  else
    printf("A tab is NOT a printable character\n");
}

Example Output

& is a printable character
A tab is NOT a printable character