title: Finding words in an array using a binary search function in C?
body: <p>I'm trying to make a program that takes a inputted string (as a command line argument), and then prints out what verbs are in the string. The list of verbs are in an array in a separate header file. The program is currently finding the verbs, but its printing the same word multiple times. Here is my code: </p>
  
  <pre><code>#include "verbs.h"
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  
  void binary_search(char *list_of_words, int size, char *target){
      int bottom= 0;
      int mid;
      int top = size - 1;
  
      while(bottom &lt;= top){
          mid = (bottom + top)/2;
          if (strcmp(&amp;list_of_words[mid], target) == 0){
              printf("%s found at location %d.\n", target, mid+1);
              break;
          }
          if (strcmp(&amp;list_of_words[mid], target) == 1){
              top= mid - 1;
          }
          if (strcmp(&amp;list_of_words[mid], target) == -1){
              bottom= mid + 1;
          }
      }
  }
  
  int main(int argc, char* argv[]){
  
      char *input;
      int i = 0;
  
      input = strtok (argv[1], " \"\n");
      while (input != NULL){
          for (i = 0; i &lt; VERBS; i++){ //VERBS is defined in verbs.h as 637
              binary_search(verbs[i], VERBS, input);
          }
          input = strtok (NULL, " ");
      }
  
      return 0;
  }
  </code></pre>
  
  <p>Any ideas?</p>