C Standard Library

C <ctype.h> - isprint() Function



The C <ctype.h> isprint() function is used to check if the given character is a printable character. A printable character is a character that occupies a printing position on a display. In the default "C" locale, a printable character are those having ASCII code greater than 0x1f (US), except 0x7f (DEL).

Other locales may consider a different selection of characters as printable characters.

Syntax

int isprint ( int ch );               

Parameters

ch Specify the character to be checked, casted to an int, or EOF.

Return Value

Returns non-zero value (i.e, true) if ch is a printable character, else returns zero (i.e, false).

Example:

The example below shows the usage of isprint() function.

#include <stdio.h>
#include <ctype.h>
 
int main (){
  char str[50] = "Hello\nWorld!";

  //replacing all non-printable 
  //characters with @ in str
  int i = 0;
  while(str[i]) {
    if(!isprint(str[i]))
      str[i] = '@';
    i++;
  }

  //displaying the output
  printf("str contains: %s", str);  
  return 0;
}

The output of the above code will be:

str contains: Hello@World!

❮ C <ctype.h> Library