ispunct()函數檢查字符是否為標點符號。此函數定義的術語“punctuation”包括所有可打印字符,既不是字母數字字符也不是空格。例如“ @”,“ $”等。此函數在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 <stdio.h>
#include <ctype.h>
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 <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: ! " # $ % & ' ( ) * +, - . /:; ? @ [ \ ] ^ _ ` { | } ~
相關用法
- C語言 strlwr()用法及代碼示例
- C語言 tolower()用法及代碼示例
- C語言 putchar()用法及代碼示例
- C++ iswpunct()用法及代碼示例
- C++ wcstoll()用法及代碼示例
- C++ ldexp()用法及代碼示例
- C++ iswblank()用法及代碼示例
- C++ iswalnum()用法及代碼示例
- C++ exp2()用法及代碼示例
- C++ raise()用法及代碼示例
- C++ feupdateenv()用法及代碼示例
- C++ gmtime()用法及代碼示例
- C++ towupper()用法及代碼示例
注:本文由純淨天空篩選整理自 ispunct() function in C。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。