iscntrl : <ctype.h> library function

iscntrl function checks whether a character is control character or not. A character is a control character If it does not occupy a printing position on a display.
For example: escape, backspace, newline etc.

Function prototype of iscntrl

int iscntrl(int c);
Function iscntrl takes a character as input in form of an integer. When we pass a value of type char to iscntrl function, corresponding ASCII value of that character is passed.

Return value of iscntrl

If passed character is a control character, then iscntrl function returns non-zero integer otherwise 0.

C program to show the use of iscntrl function

The following program is to check whether a character is control character or not.


int main(){
    char string[] = "abcd\tefgh\n";
    int index = 0;
    while(string[index] != '\0'){
            printf("string[%d] is control character\n",
                index, string[index]);
        } else {
            printf("string[%d] is not control character\n",
                index, string[index]);
    return 0;

Program Output
string[0] is not control character
string[1] is not control character
string[2] is not control character
string[3] is not control character
string[4] is control character
string[5] is not control character
string[6] is not control character
string[7] is not control character
string[8] is not control character
string[9] is control character