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 c is a whitespace character.
  • If the integer returned is zero (false), it means c is 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]);
else
printf("Not a whitespace character.\n", ch[i]);
++i;
}
return 0;
}
Copyright ©2024 Educative, Inc. All rights reserved