ispunct() 函数在 ctype.h 头文件中定义。它用于检查指定的字符是否为标点符号。标点符号是指任何图形字符,但没有字母数字字符。
int ispunct(int argument); #where argument will be a character
ispunct() 函数接受一个参数,其形式为整数,返回值为整数。当传入一个字符时,它会转换为其 ASCII 值对应的整数值。
| 参数 | 描述 | 必需/可选 |
|---|---|---|
| 参数 | 要检查的字符 | 必需 |
如果给定字符是标点符号,ispunct() 返回一个非零整数,否则返回零。当传入一个标点符号时,我们将得到一个不同的非零整数。
| 输入 | 返回值 |
|---|---|
| 零 | 如果参数不是标点符号 |
| 非零数字 | 如果参数是标点符号 |
#include <stdio.h>
#include <ctype.h>
int main() {
char ch;
int output;
ch = ':';
output = ispunct(ch);
if (output == 0) {
printf("The given %c is not a punctuation", ch);
} else {
printf("The given %c is a punctuation", ch);
}
return 0;
}
输出
The given : is a punctuation
#include <stdio.h>
#include <ctype.h>
int main()
{
int k;
printf("All punctuations in C: \n");
// Through all ASCII characters
for (k = 0; k <= 127; ++k)
if(ispunct(k)!= 0)
printf("%c ", k);
return 0;
输出
All punctuations in C:
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~