New course! Every coder should learn Generative AI!
Try a free lesson+ 1
Found this for you the words array must be sorted prior to passing to search function.
void search(char string[][20],int n,char word[])
{
int lb, mid, ub;
lb = 0; //lower bound to 0
ub = n; //upper bound to n
do
{
mid = (lb + ub) / 2; //finding the mid of the array
if ((strcmp(word,string[mid]))<0) //compare the word with mid
ub = mid - 1; //if small then decrement ub
else if ((strcmp(word,string[mid]))>0)
lb = mid + 1; //if greater then increment lb
/*repeat the process till lb doesn't becomes ub and string is found */
} while ((strcmp(word,string[mid])!=0) && lb <= ub);
if ((strcmp(word,string[mid]))==0) //if string is found
printf("SEARCH SUCCESSFUL \n");
else //if not found
printf("SEARCH FAILED \n");
}