I'm trying to search for a word in an array of strings, everytime it gets to the while loop it just loops infinitely. It's getting the words and comparing just that when it gets to the second else,
It just takes a fat dump. Can anyone help? So damn frustrating. Note, I tried comparing strings, cstrings, stings.c_str() and cstrings, same thing, it just a loops.

int binarySearch(string *dictionary, char word[])
{

    int low = 0;
    int high = lexiSize;
    int med = (high + low)/2;

    bool found = false;

    while(!found && low < high)
    {
        med = (high + low)/2;

        if(dictionary[med] == word)
        {
            found = true;
            return med;
        }
        if(dictionary[med] > word)
        {

            med = high;
        }
        else
        {
            med = low;
        }
    }

    return -1;
}

Never mind, I'm an idiot.

Ok. Explain yourself! :-) You obviously fixed it, but others may benefit from your "discovery"...

med = high;
}
else
{
med = low;

These should be reversed IE

     high = med;
    }
    else
    {
    low = med;

Stupid mistake that I've made on more than one occasion

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.