isspace <ctype.h> <cctype>
原文:https://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; }
這段代碼逐個字符地打印出c語言字符串,將任何空白字符替換成一個換行符。輸出:
Example
sentence
to
test
isspace
請參閱:
isgraph 檢測字符是否為可顯示字符(函數)
ispunct 檢測字符是否為標點符號(函數)
isalnum 檢查字符是否是字母或者數字(函數)
isspace 檢測字符是否為空白(函數)
最後更新:2017-04-02 06:52:08