C Library Functions -isprint()
C Standard Library - <ctype.h>
Description
C Library Functionsint isprint(int c)Checks whether the passed character is printable. Printable characters are characters that are non-control characters.
Declaration
Below is the declaration of the isprint() function.
int isprint(int c);
Parameter
- c-- This is the character to be checked.
Return Value
If c is a printable character, the function returns a non-zero value (true); otherwise, it returns 0 (false).
Example
The following example demonstrates the usage of the isprint() function.
#include <stdio.h>
#include <ctype.h>
int main()
{
int var1 = 'k';
int var2 = '8';
int var3 = '\t';
int var4 = ' ';
if( isprint(var1) )
{
printf("var1 = |%c| 是可打印的\n", var1 );
}
else
{
printf("var1 = |%c| 是不可打印的\n", var1 );
}
if( isprint(var2) )
{
printf("var2 = |%c| 是可打印的\n", var2 );
}
else
{
printf("var2 = |%c| 是不可打印的\n", var2 );
}
if( isprint(var3) )
{
printf("var3 = |%c| 是可打印的\n", var3 );
}
else
{
printf("var3 = |%c| 是不可打印的\n", var3 );
}
if( isprint(var4) )
{
printf("var4 = |%c| 是可打印的\n", var4 );
}
else
{
printf("var4 = |%c| 是不可打印的\n", var4 );
}
return(0);
}
Let us compile and run the above program, which will produce the following result:
var1 = |k| 是可打印的 var2 = |8| 是可打印的 var3 = | | 是不可打印的 var4 = | | 是可打印的other extensions