title: Reading data from a text file in C?
body: <p>So I'm pretty new at reading data from a text file in C. I'm used to getting input using scanf or hard coding.</p>
  
  <p>I am trying to learn how to not only read data from a text file but manipulate that data.  For example, say a text file called bst.txt had the following information used to perform operations on a binary search tree:</p>
  
  <pre><code>insert 10
  insert 13
  insert 5
  insert 7
  insert 20
  delete 5
  delete 10
  ....
  </code></pre>
  
  <p>With that example, I would have the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main()
  { 
    FILE *fptr;
    char *charptr;
    char temp[50];
  
    fptr = fopen("bst.txt", "r");
  
    while(fgets(temp, 50, fptr) != NULL)
    {
      charptr = strtok(temp, " ");
  
      while(charptr != NULL)
      {
        charptr = strtok(NULL, " ");
      }
    }
  
  return 0;
  }
  </code></pre>
  
  <p>I know that within the first while loop strtok() splits each line in the text file and within the second while loop strtok() splits off when the program recognizes a space, which in this case would separate the operations from the integers.</p>
  
  <p>So my main question is, after, for example, the word "insert" is separated from the integer "10", how do I get the program to continue like this:</p>
  
  <pre><code>if(_____ == "insert")
  {
    //read integer from input file and call insert function, i.e. insert(10);
  }
  </code></pre>
  
  <p>I need to fill in the blank.</p>
  
  <p>Any help would be greatly appreciated! </p>