title: Listing a linked list
body: <p>I wrote a program. It takes data from a text file to a linked list word by word. But there is a problem at listing the words.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  typedef struct list
  {
      char *data;
      struct list *next;
  } node;
  
  int main()
  {
      int i;
      char *word = NULL;
      char line[1000];
      node *root,*temp;
  
      root = (node *) malloc(sizeof(node));
      temp = root;
      FILE *f = fopen("test.txt","r");
      while (fgets( line, sizeof(line), f ))
          for (word = strtok(line, " "); word; word = strtok(NULL, " "))
          {
              temp-&gt;data = word;
              temp-&gt;next=(node *) malloc(sizeof(node));
              temp=temp-&gt;next;
          }
      fclose(f);
      temp =root;
      for(i=0; i&lt;10; i++)
      {
          printf("%s\n",temp-&gt;data);
          temp=temp-&gt;next;
      }
      return 0;
  }
  </code></pre>