What is isspace() in C?
The isspace() function checks whether the character passed to it is a whitespace character or not. The whitespace characters in C are:
| Character | Name |
|---|---|
| ’ ’ | Space |
| ‘\t’ | Horizontal tab |
| ‘\n’ | Newline |
| ‘\v’ | Vertical tab |
| ‘\f’ | Feed |
| ‘\r’ | Carriage return |
Library
#include<ctype.h>
Declaration
Below is the declaration of isspace() in C,
int isspace(int c);
where c is the character to be checked.
Return Value
The function returns an integer value:
- If the integer returned is non-zero (true), it means
cis a whitespace character. - If the integer returned is zero (false), it means
cis not a whitespace character.
Code
#include <stdio.h>#include <ctype.h>int main(){char ch[] = {' ', '\t', '\n', '\v', '\f', '\r', 'a', 'Z', '%', '7'};int i = 0;while (i < 10) {if(isspace(ch[i]))printf("Whitespace character.\n", ch[i]);elseprintf("Not a whitespace character.\n", ch[i]);++i;}return 0;}
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved