头文件:#inlude <ctype.h>
ispunct() 函数用来检测一个字符是否为标点符号或特殊字符,其原型为:
int ispunct(int c);
【参数】c 为需要检测的字符。
【返回值】若 c 为标点符号或特殊符号(非空格、非数字和非英文字母)返回非 0 值,否则返回 0。
注意,此为宏定义,非真正函数。
【实例】列出字符串str 中的标点符号或特殊符号。
- #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;
- }
输出结果: