Easy Tutorial
❮ C Exercise Example64 C Examples Printf Float ❯

C Library Function - isprint()

C Standard Library - <ctype.h>

Description

The C library function int isprint(int c) checks whether the passed character is printable. A printable character is a character that is not a control character.

Declaration

Here is the declaration for the isprint() function.

int isprint(int c);

Parameters

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 use 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| is printable\n", var1 );
   }
   else
   {
      printf("var1 = |%c| is not printable\n", var1 );
   }
   if( isprint(var2) )
   {
      printf("var2 = |%c| is printable\n", var2 );
   }
   else
   {
      printf("var2 = |%c| is not printable\n", var2 );
   }
   if( isprint(var3) )
   {
      printf("var3 = |%c| is printable\n", var3 );
   }
   else
   {
      printf("var3 = |%c| is not printable\n", var3 );
   }
   if( isprint(var4) )
   {
      printf("var4 = |%c| is printable\n", var4 );
   }
   else
   {
      printf("var4 = |%c| is not printable\n", var4 );
   }

   return(0);
}

Let's compile and run the above program, which will produce the following result:

var1 = |k| is printable
var2 = |8| is printable
var3 = |    | is not printable
var4 = | | is printable

C Standard Library - <ctype.h>

❮ C Exercise Example64 C Examples Printf Float ❯