Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

c

What is isprint() in C?

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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;
}

RELATED TAGS

c

CONTRIBUTOR

Syed Muhammad Ali Mustafa
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring