iscntrl() function in C

Using the iscntrl() function in C

The iscntrl() function in C is used to check whether a character is a control character. The function takes a character as input and returns a non-zero value if the character is a control character, or zero if the character is not a control character.

Here is an example of how to use the iscntrl() function:

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

int32_t main(int32_t argc, char const *argv[])
{
    char c = '\n';

    int32_t result = iscntrl(c);

    if (result > 0x00)
    {
        printf("The character is a control digit.\n");
    }
    else
    {
        printf("The character is not a control digit.\n");
    }

    return 0;
}

The iscntrl() function takes a character as input and returns a non-zero value if the character is a control character, or zero if the character is not a control character. In this example, the character '\n' is a control character, so the function will return a non-zero value and the printf() statement will print the output.

Explore the complete list of functions available in ctype header in C standard library.

0
Subscribe to my newsletter

Read articles from Embedded DeepDive directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Embedded DeepDive
Embedded DeepDive

Driving innovation in embedded systems, IoT, and FPGA/SOC development. Delivering cutting-edge solutions, expert technical services, and empowering the tech community with tutorials and practical guides.