title: Malloc struct printing error in C
body: <p>I'm trying to write a program which reads a .bin file into dynamically allocated structs.
  It <strong>seems</strong> to be doing what I want, up until I need to print the results. I'm met with an endless loop of the same struct over and over again, instead of each struct just once. The code is as follows:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  #include&lt;time.h&gt;
  
  main(){
      //File pointer
      FILE *binFile = NULL;
  
      //Struct declaration
      typedef struct flightData_struct {
          char flightNum[7];
          char origCode[5];
          char destCode[5];
          int timeStamp;
          struct flightData_struct* next;
      } flightData;
      flightData myFlightData;
      struct flightData_struct *head;
      struct flightData_struct *tail;
  
      //Opening file
      printf("Opening file...\n");
  
      binFile = fopen("acars.bin", "rb");
      if (binFile == NULL){
          printf("ERROR: Could not open file. Please try again.");
          return -1;
      }
  
      //Malloc'ing first struct
      struct myflightData *point = (struct myFlightData*) malloc(sizeof(flightData));
      fread(point, sizeof(flightData), 1, binFile);
  
      head = point;
      tail = point;
  
      //Malloc'ing structs
      while (!feof(binFile)){
          flightData *temp = (struct flightData*) malloc(sizeof(flightData));
          fread(temp, sizeof(flightData), 1, binFile);
          temp-&gt;next = NULL;
          tail-&gt;next = temp;
          tail = tail-&gt;next;
      }
  
      tail = head;
  
      while (tail != 0){
          int t;
          t = tail-&gt;timeStamp;
          time_t time = t;
          printf("%s| %s| %s| %s\n\n", tail-&gt;flightNum, tail-&gt;origCode, tail-&gt;destCode, asctime(gmtime(&amp;time)));
      }
  
      //Closing file
      printf("Closing file...");
      fclose(binFile);
      return 0;
  
  }
  </code></pre>
  
  <p>And this is the output I get from it (it seems to loop infinitely).</p>