0

我需要比较两个字符串是否相等(不区分大小写),但我的实现在编译时返回了很多警告。

我的实现:

//The word array will contain any number of strings of varying lengths
//string is the word to compare to
char **wordArray, char*string;

int i, sizeOfArray = 10

for(i = 0; i < 10; i++)
{
    //Return 1 if the string is seen in the array 
    if(strcmp(tolower(wordArray[i]), tolower(string)) == 0)
        return 1;
}

return 0;

我收到以下警告:

warning: passing argument 1 of ‘tolower’ makes integer from pointer without a cast [enabled by default]

note: expected ‘int’ but argument is of type ‘char *’

initialization makes pointer from integer without a cast [enabled by default]

我该如何实现这个

4

2 回答 2

5

tolower不会使整个字符串小写,只是一个字符。你需要把它放在一个循环中来做你正在尝试的事情。

您的系统可能具有strcasecmp(3)(UNIXy) 或_stricmp(windows) 功能,这对您来说会更方便(尽管不是标准的)。

strcasecmp POSIX 中,因此如果您选择那条路线,它可能非常便携。

于 2013-07-27T16:29:25.203 回答
1

利用stricmp(wordArray[i],string)

代替strcmp(tolower(wordArray[i]), tolower(string))

于 2013-07-27T16:32:50.287 回答