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