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: ! " # $ % & ' ( ) * +, - . / : ; ? @ [ ] ^ _ ` { | } ~