What is isprint() in C?

The isprint() function checks whether or not the character passed to it is a printable character.

Printable characters in C
Printable characters in C

Library

#include<ctype.h>

Declaration

Below is the declaration of isprint() in C, where c is the character to be checked:

int isprint(int c);

Return value

The function returns an integer value.

If the integer returned is non-zero (true), it means c is a printable character.

If the integer returned is zero (false), it means c is not a printable character.

Code

#include <stdio.h>
#include <ctype.h>
int main()
{
int count = 0; // store the count of printable characters
int i = 0;
while (i < 256) //0 to 255 ASCII characters
{
if(isprint(i) != 0)
// if character is printable,
// print it and increase count by 1
{
printf("%c ", i);
++count;
}
++i;
}
//print the count
printf("\nThere are %d printable characters in C.\n", count);
return 0;
}

Free Resources

Copyright ©2024 Educative, Inc. All rights reserved