當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


C語言 isalpha用法及代碼示例

C語言ctype頭文件(ctype.h)中isalpha函數的用法及代碼示例。

用法:

int isalpha ( int c );
檢查字符是否為字母
檢查是否c是一個字母。

注意,什麽是字母取決於所使用的語言環境。在默認情況下"C"區域設置,構成字母的隻是其中一個返回true的內容isupper或者islower

在其他語言環境中,字母字符是為其指定字符的字符isupper或者islower會傳回true,或其他語言環境明確將其視為字母(在這種情況下,該字符不能為iscntrlisdigitispunct或者isspace)。

有關不同之處的詳細圖表ctype函數針對標準ANSII字符集的每個字符返回,請參見<cctype>標頭。

在C++中,此函數的locale-specific模板版本(isalpha)存在於標題中<locale>

參數

c
要檢查的字符,強製轉換為int, 或者EOF

返回值

不同於零的值(即,true)如果確實c是一個字母。零(即false) 否則。

示例

/* 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

相關用法


注:本文由純淨天空篩選整理自C標準庫大神的英文原創作品 C isalpha function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。