C programming ctype.h function - int isprint(int c)

ht‮t‬ps://www.theitroad.com

The int isprint(int c) function in the ctype.h library of C programming is used to determine whether a given character is a printable character, including space.

The isprint() function takes a single integer argument c, which is the character to be checked. The function returns an integer value, which is nonzero if the character is a printable character (including space), and zero otherwise.

Here's an example of how to use the isprint() function in C:

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

int main() {
    char c = ' ';
    if (isprint(c)) {
        printf("%c is a printable character\n", c);
    } else {
        printf("%c is not a printable character\n", c);
    }
    return 0;
}

In this example, the isprint() function is used to check whether the character ' ' (space) is a printable character. Since ' ' is a printable character, the function returns a nonzero value, and the output will be: ' ' is a printable character'.

If the character had been a non-printable character such as '\n' (newline), the isprint() function would return zero, and the output would be: '\n' is not a printable character'.