Question
How to read structs from file and store them in array (c programming) i have an array called flights that stores structs of type flight.
How to read structs from file and store them in array (c programming)
i have an array called flights that stores structs of type flight. My program is able to store up to 5 flights in memory and i am able to call a write function that writes these structs into a binary file using fwrite(flights, sizeof(flight_t), size, fp) where size tracks the index of the flight array up until 5. I am now trying to read the structs that have been written into the file using fread(&flight, sizeof(flight_t), size, fp) within a for loop (i = 0; i This doesnt work as my display function that prints out the flights in memory prints("no flights") meaning the array is empty. So my question in the end is how do i read the structs from a file by calling a function and store them into my array so that it works? Further info: my flights array and size variable are declared in main but i want to call the read and write functions
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started