吾爱程序员:这里有好玩的游戏和软件
当前位置:首页C语言教程 → C语言中的ispunct()函数

C语言中的ispunct()函数

来源:网络 | 更新时间:2022-01-13 20:58:37
ispunct()函数检查一个字符是否是标点字符。此函数定义的“标点符号”包括所有既不是字母数字也不是空格的可打印字符。例如'@'、'$'等。 这个函数在ctype.h头文件中定义。 句法:
int ispunct(int ch); 
ch:要检查的字符。
返回值:如果字符是标点符号,函数返回非零,否则返回零。 
// Program to check punctuation
#include <stdio.h>
#include <ctype.h>
int main()
{
// The punctuations in str are '!' and ','
char str[] = "welcome! to GeeksForGeeks, ";

int i = 0, count = 0;
while (str[i]) {
if (ispunct(str[i]))
count++;
i++;
}
printf("Sentence contains %d punctuation"
" characters.n", count);
return 0;
}
输出:
Sentence contains 2 punctuation characters.
// C program to print all Punctuations
#include <stdio.h>
#include <ctype.h>
int main()
{
int i;
printf("All punctuation characters in C"
" programming are: n");
for (i = 0; i <= 255; ++i)
if (ispunct(i) != 0)
printf("%c ", i);
return 0;
}
输出:
All punctuation characters in C programming are: 
! " # $ % & ' ( ) * +, - . / : ;  ? @ [  ] ^ _ ` { | } ~
 

最新文章

热点资讯

手游排行榜

CopyRight 2020-2030吾爱程序员

鄂ICP备2021004581号-8

本站资源收集于网络,如有侵权请联系我们:35492删除0109@qq.com