This program is a dictionary program. I am loading a list of words from a file, sorting as I insert. The program also has a search function that uses the same code. Some of the words inserted into the array are in the wrong order. Am I missing something with this function?
This program is being compiled on Debian Linux with the 4.1.2 gcc compiler.
Thanks in advance.
Code:int indexOfWord( char ** dictionary, int count, char *word ) { int lowerBound = 0; int upperBound = count - 1; int midPoint = 0; int strCompResults = 0; while (lowerBound < upperBound ) { midPoint = (upperBound + lowerBound)/2; strCompResults = strcmp(word,dictionary[midPoint]); if ( strCompResults == 0) return midPoint; else if ( strCompResults > 0) lowerBound = midPoint + 1; else upperBound = midPoint - 1; } return midPoint * -1; }



LinkBack URL
About LinkBacks


