function
<cctype>

iscntrl

int iscntrl ( int c );
Check if character is a control character
Checks whether c is a control character.

A control character is a character that does not occupy a printing position on a display (this is the opposite of a printable character, checked with isprint).

For the standard ASCII character set (used by the "C" locale), control characters are those between ASCII codes 0x00 (NUL) and 0x1f (US), plus 0x7f (DEL).

For a detailed chart on what the different ctype functions return for each character of the standard ANSII character set, see the reference for the <cctype> header.

In C++, a locale-specific template version of this function (iscntrl) exists in header <locale>.

Parameters

c
Character to be checked, casted to an int, or EOF.

Return Value

A value different from zero (i.e., true) if indeed c is a control character. Zero (i.e., false) otherwise.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* iscntrl example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
  int i=0;
  char str[]="first line \n second line \n";
  while (!iscntrl(str[i]))
  {
    putchar (str[i]);
    i++;
  }
  return 0;
}


This code prints a string character by character until a control character that breaks the while-loop is encountered. In this case, only the first line would be printed, since the line ends with '\n', which is a control character (ASCII code 0x0a).

See also