C语言 isspace() 函数用来检测一个字符是否是空白符。在默认情况下,空白符包括:
| 字符 | ASCII码 (十六进制) | 说明 (缩写) |
|---|---|---|
| ' ' | 0x20 | 空格 (SPC) |
| '/t' | 0x09 | 水平制表符 (TAB) |
| '/n' | 0x0a | 换行符 (LF) |
| '/v' | 0x0b | 垂直制表符 (VT) |
| '/f' | 0x0c | 换页 (FF) |
| '/r' | 0x0d | 回车 (CR) |
头文件:ctype.h
语法/原型:
int isspace(int c);
参数 c 表示要检测的字符。
返回值:返回值为非 0(真)表示c是空白符,返回值为 0(假)表示c不是空白符。
【实例】使用C语言 isspace() 函数检测字符串中是否存在空白字符,如果存在,请替换为换行符。
#include <stdio.h>
#include <ctype.h>
int main()
{
char c;
int i = 0;
char str[] = "Linux C++/tPython Shell/nC# Java/n";
while (str[i])
{
c = str[i];
if (isspace(c)) c = '/n';
putchar(c);
i++;
}
return 0;
}
运行结果:
Linux
C++
Python
Shell
C#
Java
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/22498.html