title: C - Not properly reading data from a txt file into a linked list
body: <p>So, I am new to C and I am trying to read data from a .txt file into a linked list. I have created an insert function to place each value in the .txt file into the a node in the list. When i try to print out all the data, it just displays the last value in the txt file. </p>
  
  <p>For example:
  There are three values in the txt file. 
  When i try to print all the values, it will only print the 3rd value, THREE times.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>#include "action.h"
  
  
  void insert(ListPtr *ptr, arPtr *sPtr);
  void printList( ListPtr ptr);
  
  int main(void){
  int i,num;
  
  
  // initialize the file pointer
  FILE *ptr;//Daily
  FILE *PTR;//Group
  ListPtr startPtr = NULL;
  arPtr dataPtr;
  
  dataPtr = (arPtr) malloc( sizeof( AR));
  
  
  //dataPtr = {0,0,0,"",""};
  
  //dataPtr = malloc(sizeof ( AR));
  
  int choice = 0;
  char groupFile[20];
  char dailyFile[20];
  dataPtr-&gt;location[2] = '\0';
  dataPtr-&gt;id[6] = '\0';
  
  
  // Step one: Ask the user what the group file is. 
  printf("What is the name of the Daily File you want to load?\nFile Name:\t");
  scanf("%s",dailyFile);
  
  
  /////////////////////////////////////////////////////////////////////////////////////////////
  //              Read from the group File
  if((ptr = fopen(dailyFile,"r+")) == NULL){
  
      printf("We could not find that Daily File, We will open a new file for you to work with.");
  
      ptr = fopen(dailyFile,"w");
      choice = 1;
  }
  else{
  
      while(!feof(ptr)){
  
  //      fread(dataPtr,sizeof(struct ActionReport),1,ptr);
          printf("Before Scanning");
          fscanf(ptr, "%4d%6s%2s",&amp;(dataPtr-&gt;startTime), dataPtr-&gt;id, dataPtr-&gt;location);
          fgets(dataPtr-&gt;description,50,ptr);
  
      //  if (dataPtr != NULL){
  
          printf("After Scanning\n\n");
  
          //check the value that was read from the file
          printf("%4d\t%6s\t%2s\t%10s",dataPtr-&gt;startTime,dataPtr-&gt;id,dataPtr-&gt;location,dataPtr-&gt;description);
  
          insert(&amp;startPtr,&amp;dataPtr);
  
  
          //check the value that was placed into the linked list
          printf("%4d\t%6s\t%2s\t%10s",startPtr-&gt;ARdata-&gt;startTime,startPtr-&gt;ARdata-&gt;id,startPtr-&gt;ARdata-&gt;location,startPtr-&gt;ARdata-&gt;description);
  
      }//end while
  fclose(ptr);
  }//elsei
  
  printList(startPtr);
  </code></pre>