函式
<cctype>

isalpha

int isalpha ( int c );
檢查字元是否為字母
檢查 c 是否是字母。

請注意,什麼被視作字母取決於所使用的區域設定;在預設的“C”區域設定中,只有 isupperislower 返回 true 的字元才構成字母。

使用其他區域設定時,字母字元是 isupperislower 會返回 true 的字元,或者是該區域設定明確認為是字母的其他字元(在這種情況下,該字元不能是 iscntrlisdigitispunctisspace)。

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

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

引數

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

返回值

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

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* isalpha example */
#include <stdio.h>
#include <ctype.h>
int main ()
{
  int i=0;
  char str[]="C++";
  while (str[i])
  {
    if (isalpha(str[i])) printf ("character %c is alphabetic\n",str[i]);
    else printf ("character %c is not alphabetic\n",str[i]);
    i++;
  }
  return 0;
}

輸出
character C is alphabetic
character + is not alphabetic
character + is not alphabetic


另見