The isspace() function defined in the ctype.h header file. It helps to check the specified character is a white-space character or not.
int isspace(int argument); #where argument will be a character
The isspace() function takes a single parameter and is in the form of an integer and the return value should be an integer. When a character is passed it is converted into the integer value corresponding to its ASCII value. The white-space characters are,
Parameter | Description | Required / Optional |
---|---|---|
argument | The character to be checked | Required |
If the given character is a white-space, isspace() returns a non-zero integer else zero. When a white-space character is passed we will get a different non-zero integer.
Input | Return Value |
---|---|
Zero | If the parameter isn't a white-space |
Non zero number | If the parameter is a white-space |
#include <stdio.h>
#include <ctype.h>
int main()
{
char ch;
int output;
printf("Please enter a character: ");
scanf("%c", &ch;);
output = isspace(ch);
if (output == 0)
{
printf("The given character is not a white-space.");
}
else
{
printf("The given character is a white-space.");
}
return 0;
}
Output:
Please enter a character: 7 The given character is not a white-space.
#include <stdio.h>
#include <ctype.h>
int main() {
char ch;
int output;
ch = '\n';
output = isspace(c);
if (output == 0) {
printf("%c is not a white-space", ch);
} else {
printf("%c is a white-space", ch);
}
return 0;
}
Output:
\n is a white-space