C 標(biāo)準(zhǔn)庫(kù) <ctype.h>
ispunct()函數(shù)檢查字符是否為標(biāo)點(diǎn)符號(hào)。
ispunct()函數(shù)的原型是:
int ispunct(int argument);
如果傳遞給ispunct()函數(shù)的字符是標(biāo)點(diǎn)符號(hào),則它返回一個(gè)非零整數(shù)。如果不是,則返回0。
在C語(yǔ)言編程中,char字符在內(nèi)部被視為整數(shù)。這就是為什么要ispunct()使用整數(shù)參數(shù)的原因。
ispunct()函數(shù)在ctype.h頭文件中定義。
#include <stdio.h>
#include <ctype.h>
int main() {
char c;
int result;
c = ':';
result = ispunct(c);
if (result == 0) {
printf("%c 不是標(biāo)點(diǎn)符號(hào)", c);
} else {
printf("%c 是標(biāo)點(diǎn)符號(hào)", c);
}
return 0;
}輸出結(jié)果
: 是標(biāo)點(diǎn)符號(hào)
#include <stdio.h>
#include <ctype.h>
int main()
{
int i;
printf("C中的所有標(biāo)點(diǎn)符號(hào): \n");
//遍歷所有ASCII字符
for (i = 0; i <= 127; ++i)
if(ispunct(i)!= 0)
printf("%c ", i);
return 0;
}輸出結(jié)果
C中的所有標(biāo)點(diǎn)符號(hào):
! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~