ispunct()函数检查字符是否为标点字符。
此函数定义的术语“标点符号”包括所有可打印的字符,这些字符既不是字母数字也不是空格。例如“ @”,“ $”等。
此函数在ctype.h头文件中定义。
int ispunct(int ch);
ch: character to be checked.
Return Value : function return nonzero
if character is a punctuation character;
otherwise zero is returned.
// Program to check punctuation
#include
#include
int main()
{
// The puncuations 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
#include
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:
! " # $ % & ' ( ) * +, - . / : ; ? @ [ \ ] ^ _ ` { | } ~
想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。