0

so, when i try this code:

bool lookup(string s)

{ int start = 0; int max = WORDS - 1;

while (start <= max)
{
    int middle = (start + max) / 2;

    if (strcmp(s, dictionary.words[middle].letters == 0))
    {
        return true;
    }
    else if (strcmp(s, dictionary.words[middle].letters < 0))
    {
        start = middle + 1;
    }
    else
    {
        max = middle - 1;
    }
}
return false;

} I get these error messages:

scramble.c:396:48: error: comparison of array 'dictionary.words[middle].letters' equal to a null pointer is always false [-Werror,-Wtautological-pointer-compare] ...dictionary.words[middle].letters == 0)) ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~ ~ scramble.c:396:23: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Werror,-Wint-conversion] ...dictionary.words[middle].letters == 0)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/string.h:144:50: note: passing argument to parameter '__s2' here ...char *__s1, const char *__s2) ^ scramble.c:400:28: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Werror,-Wint-conversion] ...dictionary.words[middle].letters < 0)) ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/string.h:144:50: note: passing argument to parameter '__s2' here ...char *__s1, const char *__s2) ^ 3 errors generated. make: *** [scramble] Error 1

So, from going over the code, i thought dictionary.words[].letters (from load) was the dictionary to use for lookup, and string s was the word i am trying to find in the dictionary. wondering why these two are incompatible. Thanks for any help!

1

Misplaced parenthesis? The call to strcmp is not "closed" properly here
if (strcmp(s, dictionary.words[middle].letters == 0)) (and in the else if). The syntax is strcmp(s1,s2)

2
  • Ahh, that makes sense, so close the strcmp before the equivalence. Thanks again Dino!! I'll change it tonight and let ya know – G-REG May 10 '17 at 13:57
  • You also have you logic backwards, when your string comes before the string in middle--> max = mid -1 and vice versa, – Arsenal Vakili May 12 '17 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .