函式
<cctype>

ispunct

int ispunct ( int c );
檢查字元是否是標點符號
檢查 c 是否是標點符號。

標準"C"在 locale 中,標點符號字元是指所有圖形字元(如 isgraph 中所述)但非字母數字字元(如 isalnum 中所述)。

其他 locale 可能將不同選擇的字元視為標點符號字元,但無論如何它們都是 isgraph 字元,但不是 isalnum 字元。

有關不同ctype函式為標準 ANSII 字元集中的每個字元返回的值,請參閱 <cctype> 標頭檔案的參考。

在 C++ 中,此函式的一個 locale 特定模板版本(ispunct)存在於標頭檔案 <locale> 中。

引數

c
要檢查的字元,轉型為int型別,或EOF.

返回值

如果 c 確實是空白字元,則返回一個非零值(即true) 如果 c 確實是標點符號字元。零(即false)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* ispunct example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
  int i=0;
  int cx=0;
  char str[]="Hello, welcome!";
  while (str[i])
  {
    if (ispunct(str[i])) cx++;
    i++;
  }
  printf ("Sentence contains %d punctuation characters.\n", cx);
  return 0;
}

輸出
Sentence contains 2 punctuation characters.


另見