Those characters that occupies printing space are known as printable characters.
Printable characters are just the opposite of control characters which can be checked using iscntrl().
C isprint() Prototype
int isprint( int arg );
Function isprint()
takes a single argument in the form of an integer and returns a value of type int
.
Even though, isprint()
takes integer as an argument, character is passed to the function. Internally, the character is converted to its ASCII value for the check.
If a character passed to isprint()
is a printable character, it returns non-zero integer, if not it returns 0.
It is defined in <ctype.h> header file.
Example: C isprint() function
#include <ctype.h>
#include <stdio.h>
int main()
{
char c;
c = 'Q';
printf("Result when a printable character %c is passed to isprint(): %d", c, isprint(c));
c = '\n';
printf("\nResult when a control character %c is passed to isprint(): %d", c, isprint(c));
return 0;
}
Output
Result when a printable character Q is passed to isprint(): 16384 Result when a control character is passed to isprint(): 0
Example: C Program to List all Printable Characters Using isprint() function.
#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:
The 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 { | } ~