|
As abc123 says, it depends on how your input file is formed.
The way your program looks, is in a way, where you store the info for each person on seperate lines.
Since you use a static struct in your people defines, then you could have made the input file as beeing a binary file, with a leading double to tell you how many there were stored, so you would start by reading the number of people stored, then allocate the needed number of people in your input array, and just read each people struct binary.
To clarify, the file structure would be binary and formed like:
[double to indicate number of people stored][first person][secon person] .....
The only issues this would give, is you have to take into consideration how to handle big vs. small endian, which can be solved with running every integer through ntohl() or htonl().
A binary file would also make it easier to search through it.. Just
fseek(file_pointer, SEEK_CUR, how_many_people*sizeof(people_t));
Altho should there be an illformed storage within the file, every action performed on it, would just fsck the file up even more.
This could be solved with a simple crc checking algorithm.. But thats left as an exersize for the user.
|