2025年4月28日 星期一 乙巳(蛇)年 正月廿九 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > C语言

C语言ispunct()函数:判断字符是否为标点符号或特殊字符

时间:12-30来源:作者:点击数:100

头文件:#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;
  • }

输出结果:

Sentence contains 2 punctuation characters.
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门