I'm having a lot of difficulties with this problem since there are lots of concepts that I don't know. I'm trying to treat dictionary as an array of strings as below:
bool lookup(string s)
{
int min = 0;
int max = WORDS - 1;
while ( min <= max)
{
int middle = round(max + min / 2);
for (int i = 0, n = strlen(s); i < n; i++)
if (s[i] < dictionary[middle][i])
{
max = middle -1;
}
else if (s[i] > dictionary[middle][i])
{
min = middle +1;
}
else if (s[i] == dictionary[middle][i])
{
return true;
found = true;
}
else
{
return false;
}
}
}
I really don't understand these lines:
typedef struct
{
bool found;
char letters[LETTERS + 1];
}
word;
struct
{
int size;
word words[WORDS];
}
dictionary;
Could someone please explain how can I use dictionary as an array of strings, what should I do with word to have found in my lookup function as a "declared identifier"
I'm getting these errors:
scramble.c:444:20: error: use of undeclared identifier 'words'
if (s[i] < words[middle][i])
^
scramble.c:448:25: error: use of undeclared identifier 'words'
else if (s[i] > words[middle][i])
^
scramble.c:452:26: error: use of undeclared identifier 'words'
else if (s[i] == words[middle][i])
^
scramble.c:455:13: error: use of undeclared identifier 'found'
found = true;
^
4 errors generated.
make: *** [scramble] Error 1