English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C library function isprint() usage and example

C Standard Library <ctype.h>

The isprint() function checks whether a character is a printable character.

Characters that occupy print space are called printable characters.

Printable characters are withiscntrl()The control characters checked are exactly the opposite.

C isprint() prototype

int isprint( int arg );

The isprint() function accepts a single integer parameter and returns a value of type int.

Even if isprint() takes an integer as an argument, the character is passed to the function. Internally, the character is converted to its ASCII value for checking.

If the character passed to isprint() is a printable character, it returns a non-zero integer, otherwise it returns 0.

It<ctype.h>Defined in the header file.

Example: C isprint() function

#include <ctype.h>
#include <stdio.h>
int main()
{
    char c;
    c = 'Q';
    printf("When the printable character %c is passed to isprint(), the result is: %d", c, isprint(c));
    c = '\n';
    printf("\nWhen the printable character %c is passed to isprint(), the result is: %d", c, isprint(c));
    return 0;
}

Output result

When the printable character Q is passed to isprint(), the result is: 1
When a printable character 
 Result when passed to isprint(): 0

Example: C program using isprint() function to list all printable characters.

#include <ctype.h>
#include <stdio.h>
int main()
{
   int c;
   for(c = 1; c <= 127; ++c)
   	if (isprint(c) != 0){
   	    printf("%c ", c);
   	}
   return 0;
}

Output:

Printable characters are: 
  ! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~

C Standard Library <ctype.h>