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

The int iscntrl(int c) function in the ctype.h library of C programming is used to determine whether a given character is a control character. A control character is a character that does not have a printable representation and is used to control the output of devices such as printers and terminals.

The iscntrl() 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 control character, and zero otherwise.

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

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

int main() {
    char c = '\n';
    if (iscntrl(c)) {
        printf("%c is a control character\n", c);
    } else {
        printf("%c is not a control character\n", c);
    }
    return 0;
}
Source‮www:‬.theitroad.com

In this example, the iscntrl() function is used to check whether the character '\n' (newline character) is a control character. Since '\n' is a control character, the function returns a nonzero value, and the output will be: '\n' is a control character.

If the character had been a non-control character such as 'a', the iscntrl() function would return zero, and the output would be: 'a' is not a control character.