I want to write a binary search for a string array in C.
I have written this code and it compiles with no errors but when i try to search it gives no results. Any help would be appreciated.
String is a type def. Sorry for not clarifying this in the beginning.
//Looks up word s, in dictionary.
bool lookup(string s)
{
int min = 0;
int max = dictionary.size - 1;
int mid;
bool found = false;
while (min <= max && !found)
{
mid = (min + max) /2;
if (dictionary.words[mid].letters == s)
found = true;
else if (dictionary.words[mid].letters > s)
max = mid -1;
else
min = mid + 1;
}
return found;
}
C? Isstringa typedeff'ed struct, or is thisC++?std::stringin C, and if you're using cstrings (arrays ofchar), you can't use==to compare them (or, at least not the way you think).