Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

iscntrl — C23 character classification function

`iscntrl(c)` from `<ctype.h>` returns a nonzero value when `c` is a control character in the current locale. A control character is not printable; in the initial `C` locale, newline and horizontal tab are among the members of this class.

Version: C23

Syntax

int iscntrl(int c);

iscntrl(c) from <ctype.h> returns a nonzero value when c is a control character in the current locale. A control character is not printable; in the initial C locale, newline and horizontal tab are among the members of this class.

The example classifies \n, \t, A, and space, normalizing each result with != 0. Output 1 1 0 0 shows that the first two bytes control layout, whereas the letter and printable spacing character are not control characters.

The argument must equal EOF or be representable as unsigned char; passing a negative plain char has undefined behavior. For a byte use iscntrl((unsigned char)ch), preserving EOF separately. The result follows LC_CTYPE, so do not use it as a Unicode validator or assume particular numeric code ranges.

Examples

#include <ctype.h>
#include <stdio.h>
int main(void){int values[]={'\n','\t','A',' '};printf("%d %d %d %d\n",iscntrl(values[0])!=0,iscntrl(values[1])!=0,iscntrl(values[2])!=0,iscntrl(values[3])!=0);return 0;}

Result

1 1 0 0

The example classifies `\n`, `\t`, `A`, and space, normalizing each result with `!= 0`. Output `1 1 0 0` shows that the first two bytes control layout, whereas the letter and printable spacing character are not control characters.

Sources