The isprint() function defined in the ctype.h header file. It helps to check the specified character is a printable character or not. Printable characters are those which occupies printing space and we can say that it is just opposite of control characters.
int isprint( int argument ); #where argument will be a character
The isprint() function takes a single parameter and is in the form of an integer and the return value should be an integer. When a character is passed it is converted into the integer value corresponding to its ASCII value.
Parameter | Description | Required / Optional |
---|---|---|
argument | The character to be checked | Required |
If the given character is a printable, isprint() returns a non-zero integer else zero. When a printable character is passed we will get a different non-zero integer.
Input | Return Value |
---|---|
Zero | If the parameter isn't printable |
Non zero number | If the parameter is printable |
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
ch = 'A';
printf("If printable character %c is passed to isprint(): %d", ch, isprint(ch));
c = '\n';
printf("\nIf control character %c is passed to isprint(): %d", ch, isprint(ch));
return 0;
}
Output:
If printable character A is passed to isprint(): 1 If a control character is passed to isprint(): 0
#include <stdio.h>
#include <ctype.h>
int main()
{
int k;
printf("All printable characters are:");
for(k = 1; k <= 127; ++k)
if (isprint(k)!= 0)
printf("%c ", k);
return 0;
}
Output:
All 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 { | } ~