C語言ctype頭文件(ctype.h)中isspace函數的用法及代碼示例。
用法:
int isspace ( int c );
檢查字符是否為空格
為了"C"語言環境,空格字符為以下任意一種:
' ' | (0x20) | 空間(SPC) |
'\t' | (0x09) | 水平標簽(TAB) |
'\n' | (0x0a) | 換行符(LF) |
'\v' | (0x0b) | 垂直標簽(VT) |
'\f' | (0x0c) | 飼料(FF) |
'\r' | (0x0d) | 回車(CR) |
其他語言環境可能會將字符的不同選擇視為white-spaces,但絕不會為以下字符返回true的字符isalnum。
有關不同之處的詳細圖表ctype函數針對標準ASCII字符集的每個字符返回,請參見<cctype>標頭。
在C++中,此函數的locale-specific模板版本(isspace)存在於標題中<locale>。
參數
- c
- 要檢查的字符,強製轉換為int, 或者EOF。
返回值
不同於零的值(即,true)如果確實c是空白字符。零(即false) 否則。示例
/* isspace example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
char c;
int i=0;
char str[]="Example sentence to test isspace\n";
while (str[i])
{
c=str[i];
if (isspace(c)) c='\n';
putchar (c);
i++;
}
return 0;
}
此代碼按字符打印出C字符串,用換行符替換任何空白字符。輸出:
Example sentence to test isspace |
相關用法
- C語言 isalnum用法及代碼示例
- C語言 isalpha用法及代碼示例
- C語言 isblank用法及代碼示例
- C語言 iscntrl用法及代碼示例
- C語言 isdigit用法及代碼示例
- C語言 isgraph用法及代碼示例
- C語言 islower用法及代碼示例
- C語言 isprint用法及代碼示例
- C語言 ispunct用法及代碼示例
- C語言 isupper用法及代碼示例
- C語言 isxdigit用法及代碼示例
- C語言 tolower用法及代碼示例
- C語言 toupper用法及代碼示例
注:本文由純淨天空篩選整理自C標準庫大神的英文原創作品 C isspace function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。