totn C Functions

C Language: iscntrl function
(Test for Control Character)

In the C Programming Language, the iscntrl function tests whether c is a control character.

Syntax

The syntax for the iscntrl function in the C Language is:

int iscntrl(int c);

Parameters or Arguments

c
The value to test whether it is a control character.

Returns

The iscntrl function returns a nonzero value if c is a control character and returns zero if c is not a control character.

Required Header

In the C Language, the required header for the iscntrl function is:

#include <ctype.h>

Applies To

In the C Language, the iscntrl function can be used in the following versions:

  • ANSI/ISO 9899-1990

iscntrl Example

/* Example using iscntrl by TechOnTheNet.com */

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

int main(int argc, const char * argv[])
{
    /* Define a temporary variable */
    unsigned char test;

    /* Assign a test control character to the variable */
    test = 0; /* This is NUL */

    /* Test to see if this is a control character */
    if (iscntrl(test) != 0) printf("NUL is a control character\n");
    else printf("NUL is not a control character\n");

    /* Assign a non-control character to the variable */
    test = 'T';

    /* Test to see if this is a control character */
    if (iscntrl(test) != 0) printf("%c is a control character\n", test);
    else printf("%c is not a control character\n", test);

    return 0;
}

When compiled and run, this application will output:

NUL is a control character
T is not a control character

Similar Functions

Other C functions that are similar to the iscntrl function: