title: Generating a Linked List by reading numbers from text file
body: <p>I want to read in numbers from text file and create a linked list dynamically, although I am able to do it, the last node with value of 0 is also added to the list. How can I correct this? Also I should be able to add value 0 if i want but not in this way.</p>
  
  <pre><code>    #include &lt;stdio.h&gt;
      #include &lt;stdlib.h&gt;
  
      typedef struct node {
        int data;
        struct node *next;
      }node;
  
  
      int main(int argc, char const *argv[]) {
  
        FILE *fp = fopen("data.txt", "r");
  
        node *prev = NULL;
        while(!feof(fp)){
          node *curr = malloc(sizeof(node));
  
          fscanf(fp, "%d", &amp;(curr-&gt;data));           
          fprintf(stdout, "%d--&gt;", curr-&gt;data);
  
          if(prev != NULL){
            prev-&gt;next = curr;
          }
          prev = curr;
        }
        printf("NULL\n");
  
        fclose(fp);
        return 0;
      }
  </code></pre>
  
  <p>The input file is this single column of integers
  1
  5
  2
  3
  6
  4</p>
  
  <p>The output comes like this, the 0 is not part of input
  1-->5-->2-->3-->6-->4-->0-->NULL</p>