I am trying to parse a file filled with integers (one per line, presumably EOF at the end) into an array of ints. The file will contain several thousand ints but I want o produce well designed code that will work with any size file and will do some error checking.
What is the most efficient way of figuring out the number of ints before asking malloc to reserve the memory for the array of ints?
If I use atoi() or strtol() for parsing, I presume I will have an outer loop checking if the next char is not EOF ( while (c != EOF) ) then have an inner loop parses line by line (looking for \n ??).
Should I use strtol (better error checking ? ) instead of atoi. All the ints will fit easily within a 32 bit int.
How do I go about doing this efficiently and well?
Thanks.