C isprint() Function Tutorial

In this section, we will learn what the isprint() function is and how to use it in C.

Non Printable Characters

A non-printable character is a type of character that does not have a printable character to represent itself but it has some effects on the surrounding characters.

A white space, a newline, a tab, these are examples of non-printable characters.

isprint() function in C

The `isprint()` function is used to check whether a character is printable.

The prototype of the function exists in the `ctype.h` header file and we need to include this header file in order to use ` isprint ()` function.

isprint() Function Syntax

Here’s the prototype of the ` isprint ()` function:

int isprint (int argument);

isprint() Function Parameters

This function takes one argument and that is the character that we want to check.

isprint() Function Return Value

The return value of the function is:

  • 0: If the character was not a printable character.
  • Positive value: if the character was in fact a printable character.

Example: using isprint() function in C

#include <stdio.h>
#include <ctype.h>

int main() {

    char character = '\t';
    char c2 = '\n';

    printf("The first character: %d \nThe second character: %d", isprint (character), isprint (c2));

    return  0;
}

Output:

The first character: 0

The second character: 0

In this example, both characters (tab and newline characters) are not printable and so the result is 0 for both characters.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies