C isspace() Function Tutorial

  • Post author:
  • Post category:C

In this section we will learn what the isspace() function is and how to use it in C.

isspace() function in C

The `isspace()` function is used to check whether a character is a space character.

The prototype of the function exists in the `ctype.h` header file and we need to include this header file in order to use the ` isspace ()` function.

isspace() Function Syntax

Here’s the prototype of the ` isspace ()` function:

int isspace (int argument);

isspace() Function Parameters

This function takes one argument and that is the character that we want to check.

isspace() Function Return Value

The return value of the function is:

  • 0: If the character was not a space-character.
  • Positive value: if the character was in fact a space-character.

Example: check character for space

#include <stdio.h>
#include <ctype.h>

int main() {

    char character = '\t';
    char c2 = ';';

    printf("The first character: %d \nThe second character: %d", isspace (character), isspace (c2));

    return  0;
}

Output:

The first character: 8

The second character: 0

The first character in this example is `\t` and so the result of calling the `isalpha` function is a positive value because `\t` is a space character. But the result of the second character is 0 because the actual value of the character is `;` and it’s not a space character.

Leave a Reply