ispunct()
函数的原型是
int ispunct(int argument);
如果传递给 ispunct()
函数的字符是标点符号,它将返回一个非零整数。如果不是,则返回 0。
在 C 编程中,字符在内部被视为整数。这就是为什么 ispunct()
接受一个整数参数。
ispunct()
函数定义在 ctype.h 头文件中。
示例 1:检查标点符号的程序
#include <stdio.h>
#include <ctype.h>
int main() {
char c;
int result;
c = ':';
result = ispunct(c);
if (result == 0) {
printf("%c is not a punctuation", c);
} else {
printf("%c is a punctuation", c);
}
return 0;
}
输出
: is a punctuation
示例 2:打印所有标点符号
#include <stdio.h>
#include <ctype.h>
int main()
{
int i;
printf("All punctuations in C: \n");
// looping through all ASCII characters
for (i = 0; i <= 127; ++i)
if(ispunct(i)!= 0)
printf("%c ", i);
return 0;
}
输出
All punctuations in C: ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~