ispunct

来源:互联网 发布:手游端游数据互通 编辑:程序博客网 时间:2024/06/07 14:18
头文件:#inlude <ctype.h>

ispunct() 函数用来检测一个字符是否为标点符号或特殊字符,其原型为:
int ispunct(int c);

【参数】c 为需要检测的字符。

【返回值】若 c 为标点符号或特殊符号(非空格、非数字和非英文字母)返回非 0 值,否则返回 0。

注意,此为宏定义,非真正函数。

【实例】列出字符串str 中的标点符号或特殊符号。
复制纯文本新窗口
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. int main ()
  4. {
  5. int i=0;
  6. int cx=0;
  7. char str[]="Hello, welcome!";
  8. while (str[i])
  9. {
  10. if (ispunct(str[i])) cx++;
  11. i++;
  12. }
  13. printf ("Sentence contains %d punctuation characters.\n", cx);
  14. return 0;
  15. }
#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.
0 0