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!