How would you store information read from a file into an array where each element is a structure?
How would you store information read from a file into an array where each element is a structure?
It depends on the format of the file: TXT, CSV, XML, HTML, etc. As I understand, obviously first you open the file for reading
C File I/O Tutorial - Cprogramming.com
And then you will need to define a function that takes each line and based on some delimiter (, or ; or | or simply space, etc), splits each line into separate tokens, each token corresponding to a field of your structure. This is done inside a loop reading each line of the file. During each iteration you have a local variable of the specific structure type whose fields are populated, at the end of the loop, this local element is added to your array.
Regards,
Dariyoosh