title: Find Verbs in a String
body: <p>I am trying (and having trouble) to write a program (In C) that accepts a string in the command line (eg. $ test.out "This is a string") and looks through the string to find verbs (and nouns, but if I figure out verbs, I can do nouns on my own).  </p>
  
  <p>A list of aplphabetically sorted verbs is given in the file lexicon.h, and is what I am supposed to use as my dictionary.  </p>
  
  <p>I know how to accept the string from the command line and use that input to create an array of strings, each string itself being a separate word, and I already have a working program that can do that, and that I hope to use part of for this one.</p>
  
  <p>I am supposed to create a function called binary_search(...stuffgoeshere...) and use that to search through the lexicon file and find the verb. </p>
  
  <p>I would like some suggestions or guidance on how to create a function (binary_search) that can check to see if an already separated word matches any on the list in lexicon.h.  I do not want someone to just write an answer, I would like to know why you are suggesting what you do.  Hopefully I can learn something fun out of this!  </p>
  
  <p>I know it's messy, but this is what I have so far.</p>
  
  <p>Also note that lexicon's verb array has 637 values (as seen when I make int size = 637)
  This program does not compile anymore, as I have not yet figured out how to make the binary_search function work yet.  I am trying to modify a binary search function used in an example for class, however, that one sorted numbers in a text file, not strings of characters.</p>
  
  <p>If there is anything else I should include, let me know.  Thank you for your help!  </p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;string.h&gt;
      #include "lexicon.h"
  
      int binary_search(char word[], char verbs[][], int size);
  
      int
      main(int argc, char*argv[])
      {
              char word[80];
              char str[80],
                   args[80][80];
              int counter = 0,
                  a = 0,
                  i = 0,
                  index = 0,
                  t = 0;
              while(str[a] != '\0')
              {
                      if(str[a] == ' ')
                      {
                              args[index][i] = '\0';
                              i = 0;
                              a++;
                              index ++;
                              counter ++;
                      }
                      args[index][i++] = str[a++];
              }
              args[index][i] = '\0';
              counter = counter + 1;
              printf("\nThe verbs were: ");
              int verbposition= -1;
           int size = 637;
              while(t&lt;counter)
              {
                      strcpy(word, args[t]);
                      verbposition = binary_search(word, verbs, size);
  
                      if(verbposition &gt; -1)
                              printf("%s", args[t]);
  
                      t++;
  
              }
  
              return 0;
      }
  
      int
      binary_search(char word[], char &amp;verbs[][], int size)
      {
              int bottom = 0,
        top = size - 1,
                  found = 0,
                  middle;
              while(bottom &lt;= top &amp;&amp; !found)
              {
                      middle = (bottom + top) / 2;
  
                      if(strcmp(word, verbs[middle]))
                      {
                              found = 1;
                              return = middle;
                      }
                      if(strcmp(word, verbs[middle]) &gt; 0)
                      {
                              top = middle - 1;
                      }
                      else
                              bottom = middle + 1;   
       }
              return -1;
      }
  </code></pre>