有谁知道我该如何去解压并检查我的char数组中的第一个字符是否是字母表,我需要这样做而不使用isalpha,这甚至有可能吗?如何提取并检查数组元素中的第一个字符是否是一个字母
char * spellCheck [] = {“babi”,“cmopuertr”,“3method”};
我有类似的东西,我需要能够提取该字符数组中的第3个元素中的3,这样该字将计算为拼写正确!
请帮
日Thnx
有谁知道我该如何去解压并检查我的char数组中的第一个字符是否是字母表,我需要这样做而不使用isalpha,这甚至有可能吗?如何提取并检查数组元素中的第一个字符是否是一个字母
char * spellCheck [] = {“babi”,“cmopuertr”,“3method”};
我有类似的东西,我需要能够提取该字符数组中的第3个元素中的3,这样该字将计算为拼写正确!
请帮
日Thnx
您可以使用std::isalpha
:
检查给定的字符是字母字符[...]
例子:
#include <cctype> // for std::isalpha
if (std::isalpha(str[0]))
std::cout << "The character is an alphabetic character." << std::endl;
在C语言中,你可以使用库函数isalpha
。
int isalpha(int c); //c is the character to be checked
像这样:
#include <cctype>
bool b = std::isalpha(thearray[0]);
您将使用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");
}
你到目前为止尝试过什么?你知道如何检查不在数组中的字符串中的第一个字符吗? – nhgrif
'é'是你的字母表吗?因为我认为大多数答案都假设一封信(或一个字母)只是a-z或A-Z。感谢, –