English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

Usage and example of C library function isspace()

C Standard Library <ctype.h>

The ispace() function checks whether the character is a whitespace character.

If the parameter (character) passed to the ispace() function is a whitespace character, it will return a non-zero integer. If not, it returns 0.

Function prototype of ispace()

int ispace(int argument);

When a character is passed as an argument, the corresponding ASCII value (integer) of the character is passed, rather than passing the character itself.

The ispace() function inctype.hDefined in header files.

The list of all whitespace characters in C language programming is:

CharacterDescription
' 'Space
'\n'Newline
'\t'Horizontal tab
'\v'Vertical tab
'\f'Form feed
'\r'Carriage return

Example #1Check for 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 space character.");
    }
    else
    {
        printf("Space character.");
    }
    return 0;
}

Output Result

Enter a character: 5
Not a space character.

C Standard Library <ctype.h>