曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 3181|回复: 0
打印 上一主题 下一主题

[字符串] isspace() -- 测试空白字符

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2011-12-17 12:58:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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 码。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-4 16:31 , Processed in 0.092376 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表