totn C Functions

C Language: isspace function
(Test for White-Space Character)

In the C Programming Language, the ispace function tests whether c is a white-space character such as space (' '), form feed ('\f'), new line ('\n'), carriage return ('\r'), horizontal tab ('\t'),and vertical tab ('\v').

Syntax

The syntax for the isspace function in the C Language is:

int isspace(int c);

Parameters or Arguments

c
The value to test whether it is a white-space character such as space (' '), form feed ('\f'), new line ('\n'), carriage return ('\r'), horizontal tab ('\t'),and vertical tab ('\v').

Returns

The isspace function returns a nonzero value if c is a white-space character and returns zero if c is not a white-space character.

Required Header

In the C Language, the required header for the isspace function is:

#include <ctype.h>

Applies To

In the C Language, the isspace function can be used in the following versions:

  • ANSI/ISO 9899-1990

isspace Example

/* Example using isspace by TechOnTheNet.com */

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

int main(int argc, const char * argv[])
{
    /* Define a temporary variable */
    unsigned char test;

    /* Assign a test space character to the variable */
    test = '\t'; /* This is a tab character */

    /* Test to see if this character is a space character */
    if (isspace(test) != 0) printf("Tab is a space character\n");
    else printf("Tab is not a space character\n");

    /* Assign a non-space character to the variable */
    test = 'T';

    /* Test to see if this character is a space character */
    if (isspace(test) != 0) printf("%c is a space character\n", test);
    else printf("%c is not a space character\n", test);

    return 0;
}

When compiled and run, this application will output:

Tab is a space character
T is not a space character

Similar Functions

Other C functions that are similar to the isspace function: