2013-10-03 39 views
-6

有誰知道我該如何去解壓並檢查我的char數組中的第一個字符是否是字母表,我需要這樣做而不使用isalpha,這甚至有可能嗎?如何提取並檢查數組元素中的第一個字符是否是一個字母

char * spellCheck [] = {「babi」,「cmopuertr」,「3method」};

我有類似的東西,我需要能夠提取該字符數組中的第3個元素中的3,這樣該字將計算爲拼寫正確!

請幫

日Thnx

+5

你到目前爲止嘗試過什麼?你知道如何檢查不在數組中的字符串中的第一個字符嗎? – nhgrif

+5

'é'是你的字母表嗎?因爲我認爲大多數答案都假設一封信(或一個字母)只是a-z或A-Z。感謝, –

回答

6

您可以使用std::isalpha

檢查給定的字符是字母字符[...]

例子:

#include <cctype> // for std::isalpha 

if (std::isalpha(str[0])) 
    std::cout << "The character is an alphabetic character." << std::endl; 
0

在C語言中,你可以使用庫函數isalpha

int isalpha(int c); //c is the character to be checked 
1

像這樣:

#include <cctype> 

bool b = std::isalpha(thearray[0]); 
0

你可以使用因而isalpha()方法,用C

int isalpha (int c); 

您可以使用其他方式,如果爲az和AZ

的ASCII碼條件檢查
+0

是aplha做的伎倆。 – Ozwurld

1

您將使用isalpha()功能:

#include <stdio.h> 
#include <stdlib.h> 
#include <ctype.h> //header file required for isalpha(); function 

int main(void) 
{ 
    char string[] = "Test"; 
     /* I cast the array element to an integer since the isalpha function calls for 
      an integer as a parameter 
     */ 

    if(isalpha((int) string[0])) printf("first array element is a character"); 
    else printf("first array element not a character"); 
} 
相關問題