I am not sure what is wrong, my .bin comes out to gibberish and I think I did the chain incorrectly, but I could be wrong.
Code:
#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.
FILE* binFile = fopen("acars.bin","r");
FILE* DataOut;
struct flight_struct *p =(struct flight_struct*) malloc(sizeof(flight_struct)); //malloc the first struct
fread(p,sizeof(flightRec),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(sizeof(flight_struct)); //malloc a new struct
fread(temp,sizeof(flight_struct),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 != 0 ){
int t;
t = tail -> timestamp;
time_t time = t;
printf("%s, %s, %s, %s\n\n",tail -> flightNum,tail -> originAirport,tail -> destAirport,asctime(gmtime(&time)));
tail = tail -> next;
} //starting at head traverse the list printing the leemnts of each strucure
}