ispunct <ctype.h> <cctype>
原文:https://www.cplusplus.com/reference/clibrary/cctype/ispunct/
int ispunct ( int c );
檢查字符是否是標點符號
檢查參數c是否是標點符號。任何一個不是字母或者數字(isalnum)的可顯示字符(isgraph)都是一個標點符號。
想要得到不同的ctype函數在處理每個標準ANSII字符返回值的詳細圖表,請閱讀參考<cctype>頭文件。
在C++語言中,一個特定於語言環境模版版本的ispunct函數存在於頭文件<locale>。
參數
c
待檢查字符,被轉換成一個整數或者EOF結束符。
返回值
如果事實上c是一個標點符號,返回值為非0(例如:true)。否則,返回值為0 (例如:false)。
實例
/* ispunct example */ #include <stdio.h> #include <ctype.h> int main () { int i=0; int cx=0; char str[]="Hello, welcome!"; while (str[i]) { if (ispunct(str[i])) cx++; i++; } printf ("Sentence contains %d punctuation characters.\n", cx); return 0; }
輸出:
Sentence contains 2 punctuation characters.
請參閱
isgraph 檢測字符是否為可顯示字符(函數)
iscntrl 檢查字符是否是控製字符(函數)
最後更新:2017-04-02 06:52:08