
- C Library - Home
- C Library - <assert.h>
- C Library - <complex.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <fenv.h>
- C Library - <float.h>
- C Library - <inttypes.h>
- C Library - <iso646.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdalign.h>
- C Library - <stdarg.h>
- C Library - <stdbool.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <tgmath.h>
- C Library - <time.h>
- C Library - <wctype.h>
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
C Library - iscntrl() function
The C ctype library iscntrl() function is used to check whether a given character is a control character. Control characters are non-printable characters that are used to control the operation of devices (such as printers or displays) and include characters like newline, tab, and others.
Syntax
Following is the C library syntax of the iscntrl() function −
int iscntrl(int ch);
Parameters
This function accepts a single parameters −
ch − This is the character to be checked, passed as an integer. The value should be representable as an unsigned char or be equal to EOF.
Return value
The iscntrl() function returns a non-zero value (true) if the character is a control character. Otherwise, it returns zero (false).
Example 1: Checking a newline character
This example checks if the newline character ('\n') is a control character. The function returns true, confirming that it is.
#include <stdio.h> #include <ctype.h> int main() { char ch = '\n'; // newline character if (iscntrl(ch)) { printf("The character '\\n' is a control character.\n"); } else { printf("The character '\\n' is not a control character.\n"); } return 0; }
Output
The above code produces following result −
The character '\n' is a control character.
Example 2: Checking a printable character
Here we check if the character 'A' is a control character. The function returns false, indicating that 'A' is not a control character.
#include <stdio.h> #include <ctype.h> int main() { char ch = 'A'; // printable character if (iscntrl(ch)) { printf("The character 'A' is a control character.\n"); } else { printf("The character 'A' is not a control character.\n"); } return 0; }
Output
After execution of above code, we get the following result −
The character 'A' is not a control character.