Join our newsletter for the latest updates.

C isspace()

The isspace() function checks whether a character is a white-space character or not.

If an argument (character) passed to the isspace() function is a white-space character, it returns non-zero integer. If not, it returns 0.


Function prototype of isspace()

int isspace(int argument);

When a character is passed as an argument, corresponding ASCII value (integer) of the character is passed instead of that character itself.

The isspace() function is defined in ctype.h header file.


List of all white-space characters in C programming are:

Character Description
' ' space
'\n' newline
'\t' horizontal tab
'\v' vertical tab
'\f' form feed
'\r' Carraige return

Example #1: Check white-space character

#include <stdio.h>
#include <ctype.h>
int main()
{
    char c;
    int result;

    printf("Enter a character: ");
    scanf("%c", &c);
    
    result = isspace(c);

    if (result == 0)
    {
        printf("Not a white-space character.");
    }
    else
    {
        printf("White-space character.");
    }

    return 0;
}

Output

Enter a character: 5
Not a white-space character.