isspace() c – isspace C Library function

isspace function checks whether a character is white-space character or not. White-space characters are vertical tab(‘\v’), horizontal tab(‘\t’), newline(‘\n’), form feed(‘\f’), carriage return(‘\r’), and space(‘ ‘).

Function prototype of isspace

int isspace(int c);

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

Return value of isspace

isspace() c: If passed character is a white-space character, then isspace function returns non-zero(true) integer otherwise 0(false).

C program using isspace function

Isspace c: The following program is to check whether a character is a white-space character or not.

isspace C Library function

#include <stdio.h>
#include <ctype.h>
#include <conio.h>
 
int main(){
    char string[] = "A \t";
    int index = 0;
     
    while(string[index] != '\0'){
        if(isspace(string[index])){
            printf("'%c' is a space character\n", string[index]);
        } else {
            printf("'%c' is not a space character\n", 
                string[index]);
        }
        index++;
    }
     
    getch();
    return 0;
}

Output

'A' is not a space character
' ' is a space character
'        ' is a space character