Your function lost me. Try it like this:
Code:
#include <stdio.h>
#include <string.h>
int binarySearch(char words[6][30], char target[6]);
int main(void) {
int i;
char words[6][30] = {
{"Alfa"},{"Bravo"},{"Charlie"},{"Delta"},{"Echo"},{"Foxtrot"}};
char target[30];
printf("Enter the word you are searching for: ");
fflush(stdout);
scanf("%s",target);
i=binarySearch(words,target);
if(i>-1) //zero is a legitimate array index
printf("Found it, index %d in the array\n",i);
else
printf("Target word: %s was not found in the list\n",target);
return 0;
}
int binarySearch(char words[6][30], char target[30]) {
int i, lo=0,hi=5,mid;
while(lo<=hi) {
mid = (lo + hi)/2;
i=strcmp(words[mid],target);
//helpful for debugging:
//printf("i:%d mid:%d words[mid]: %s\n",i,mid,words[mid]); getchar();
if(i>0) {
hi=mid-1;
}else if(i<0) {
lo=mid+1;
}else
return mid; //target was found, this is it's index
}
return -1; //target was not found
}