I am having trouble with this code, and I'm not sure what I'm doing wrong
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef struct flight_struct{
char flightNum[7];
char originAirport[5];
char destAirport [5];
int timestamp;
struct flight_struct *next;
} flightRec;
int main(){
struct flight_struct *head; // unchanging first node.
struct flight_struct *tail; //the conductor.
struct flight_struct *p; // first new struct
FILE* binFile = fopen("acars.bin","r");
FILE* DataOut;
p =(struct flight_struct*) malloc(sizeof(*p) + 1); //malloc the first struct\
fread(p,sizeof(*p),1,binFile); //read the file into it.
head = p; //make head point to that struct
tail = p; //make tail point to that struct
// fclose(binFile);
while (feof(binFile) == 0){
flight_struct *temp = (struct flight_struct*) malloc(1*sizeof(*temp) + 1); //malloc a new struct
fread(temp,sizeof(*temp),1,binFile); //read the next struct from acars.bin into the structure you malloc'ed
temp -> next = NULL; // add that struct to your linked list using the next memeber of the struct
tail -> next = temp; // set tail to point to the element you just added
tail = tail -> next;
} //while not eof on acars file
tail = head;
while(tail -> next != 0 ){
int t;
t = tail -> timestamp;
time_t tim = t;
printf("%s, %s, %s, %s\n\n",tail -> flightNum,tail -> originAirport,tail -> destAirport,asctime(gmtime(&tim)));
tail = tail -> next;
} //starting at head traverse the list printing the leemnts of each strucure
}
Now, what I am getting as a result is 
What I should be getting is 
Honestly I don't know what I'm doing wrong, and help would be nice. That being said, I can't use arrays so a linked list is the only way to do it.
struct flight_struct *next;in the structure you read from forces that amount of data to be read from the file into the pointer (which you then overwrite). I seriously doubt that "next" is part of the information in the datafile, so by reading it that way you are messing up the alignment of how you read the file, not to mention the issue with internal structure padding doing the same thing. Use separate freads to read each element, checking the return value (to make sure 1 thing was read each time) and the !feof() does not work the way you think it does.