如果传递给 isspace() 函数的参数(字符)是空白字符,它将返回非零整数。否则,它将返回 0。
isspace() 的函数原型
int isspace(int argument);
当一个字符作为参数传递时,传递的是该字符对应的 ASCII 值(整数),而不是字符本身。
isspace() 函数定义在 ctype.h 头文件中。
C 编程中所有空白字符的列表是
字符 | 描述 |
---|---|
' ' | 空格 |
'\n' | 换行符 |
'\t' | 水平制表符 |
'\v' | 垂直制表符 |
'\f' | 进纸符 |
'\r' | 回车符 |
示例 #1:检查空白字符
#include <stdio.h>
#include <ctype.h>
int main()
{
char c;
int result;
printf("Enter a character: ");
scanf("%c", &c);
result = isspace(c);
if (result == 0)
{
printf("Not a white-space character.");
}
else
{
printf("White-space character.");
}
return 0;
}
输出
Enter a character: 5 Not a white-space character.