原文:http://www.cplusplus.com/reference/clibrary/cctype/isspace/
int isspace ( int c );
检查字符是否是一个空白字符检查参数c是否是一个空白字符
For the purpose of this function, standard white-space characters are:
' ' (0x20) 空格字符 (SPC)
'\t' (0x09) 水平制表符(TAB)
'\n' (0x0a) 换行符 (LF)
'\v' (0x0b) 竖直制表符 (VT)
'\f' (0x0c) 翻页符 (FF)
'\r' (0x0d) 回车符(CR)
特定的编译器可能把扩展字符(0x7f以上)也定义为新增加的空白字符。
想要得到不同的ctype函数在处理每个标准ANSII字符返回值的详细图表,请阅读参考<cctype>头文件。
在C++语言中,一个特定于语言环境模版版本的isspace函数存在于头文件<locale>。
参数
c
待检查字符,被转换成一个整数或者EOF结束符。
返回值
如果事实上c是一个空白字符,返回值为非0(例如:true)。否则,返回值为0 (例如:false)。
实例
- /* isspace example */
- #include <stdio.h>
- #include <ctype.h>
- int main ()
- {
- int c;
- int i=0;
- char str[]="Example sentence to test isspace\n";
- while (str[i])
- {
- c=int(str[i]);
- if (isspace(c)) c='\n';
- putchar (c);
- i++;
- }
- return 0;
- }
/* isspace example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
int c;
int i=0;
char str[]="Example sentence to test isspace\n";
while (str[i])
{
c=int(str[i]);
if (isspace(c)) c='\n';
putchar (c);
i++;
}
return 0;
}
这段代码逐个字符地打印出c语言字符串,将任何空白字符替换成一个换行符。输出:
Example
sentence
to
test
isspace
请参阅:
isgraph 检测字符是否为可显示字符(函数)
ispunct 检测字符是否为标点符号(函数)
isalnum 检查字符是否是字母或者数字(函数)
isspace 检测字符是否为空白(函数)