title: Splitting a text file into words in C
body: <p>I have 2 types of texts which I want to split them into words.</p>
  
  <p>The first type of text file is just words divided by newline.</p>
  
  <pre><code>Milk
  Work
  Chair
  ...
  </code></pre>
  
  <p>The second type of text file is a text from a book , which has only whitespace.
  (No comas,question marks etc.)</p>
  
  <pre><code>And then she tried to run 
  but she was stunned by the view of 
  ...
  </code></pre>
  
  <p>Do you know which is the best way to do it ?</p>
  
  <p>I tried the following 2 ways but it seems I am getting segmentations.</p>
  
  <p>For the first type of text I use:</p>
  
  <pre><code>while(fgets(line,sizeof(line),wordlist) != NULL)
  {
      /* Checks Words |
      printf("%s",line);*/
      InsertWord(W,line);/*Function that inserts the word to a tree*/
  }
  </code></pre>
  
  <p>And for the second type of text I use:</p>
  
  <pre><code>while(fgets(line,sizeof(line),out) != NULL)
  {
      bp = line ;
      while(1)
      {
          cp = strtok(bp," ");
          bp = NULL ;
  
          if(cp == NULL)
              break;
  
          /*printf("Word by Word : %s \n",cp);*/
          CheckWord(Words, cp);/*Function that checks if the word from the book is the same with one in a tree */
      }
  }
  </code></pre>
  
  <p>Can you suggest anything better or correct me if am wrong on these one's ?</p>
  
  <h2>EDIT:(About segm.fault)</h2>
  
  <p>InsertWord is a function that inserts words into a tree.
  When I used this code:</p>
  
  <pre><code>for (i = 0 ; i &lt;=2 ; i++)
  {
      if (i==0)
          InsertWord(W,"A");
      if (i==1)
          InsertWord(W,"B");
      if (i==2)
          InsertWord(W,"c");
  }*/
  </code></pre>
  
  <p>The tree inserts the words just fine and prints them , too, which means my tree works fine and it's functions(they were given by our teachers ,too).
  But when I try to do the same like that :</p>
  
  <pre><code>char this_word[15];
  while (fscanf(wordlist, "%14s", this_word) == 1) 
  {
      printf("Latest word that was read: '%s'\n", this_word);
      InsertWord(W,this_word);
  }
  </code></pre>
  
  <p>I am getting errors from tree.So, I guessed it was some kind of segmentation.
  Any ideas ?</p>