isspace() 函数原型如下:
[C++] 纯文本查看 复制代码 #include <ctype.h>
int isspace(int c);
该函数检查和参数 c 是否为空白字符。空白字符包括:空格(' '),制表符('\t'),回车('\r'),换行('\n') ,垂直制表符('\v') 以及换页 ('\f') 。该函数也是个宏函数。
测试代码:
[C++] 纯文本查看 复制代码 #include <stdio.h>
#include <ctype.h>
int main()
{
char str[] = "1 2\t345\nabc\rdef\ngh\v";
int i;
for (i = 0; str[i] != 0; i++)
if (isspace(str[i]))
printf ("str[%d] is a whitespace character: %d\n", i, str[i]);
return 0;
}
运行输出: ./isspace
str[1] is a whitespace character: 32
str[3] is a whitespace character: 9
str[7] is a whitespace character: 10
str[11] is a whitespace character: 13
str[15] is a whitespace character: 10
str[18] is a whitespace character: 11 上面程序打印出了这些空白符的 ASCII 码。 |