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 |
#include<ctype.h>
Below is the declaration of isspace()
in C,
int isspace(int c);
where c
is the character to be checked.
The function returns an integer value:
c
is a whitespace character.c
is not a whitespace character.#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;}