OK there are at least two ways you can approach this, with binary data files or textual data files. Each has its pros and cons.
Binary data files are probably the easiest and more fool-proof ways of dealing with data files:
So the upside of a binary file is that its easy to read the records in a failsafe manner. The downside is that it is harder to read/edit the datafile by hand if need be.
// this is what the record might look like:
// pretend it is an employee or a student
// assuming the records are all uniform size we can figure out the number
// of records in the data file....
// the file is already open...
fseek (pFile, 0, SEEK_END);
int nRecordCount = size / sizeof(struct TMyDataRecord);
fseek(pFile, 0, SEEK_BEGIN);
for(nCount = 0; nCount < nRecordCount; nCount++)
struct TMyDataRecord newRecord;
fread(&newRecord, 1, sizeof(struct TMyDataRecord)); // read whole record in one go
// stash the record somewhere, in an array or whatever
Text files on the other hand can be hand-written if need be; the downside is that they can be more problematic to read.
Probably what I would do is group each block of data into records, delimiting them with carriage returns so the above would involve a data file that looked (roughly) like:
In which case you would peel off each record by seeking to the first (next) '\n', then parse each line read by seeking out ','...and as you may have noticed, you hit hard part #1 with the text file as data file paradigm: handling delimiters when they are embedded in the quotes. This further lends weight to the argument of the ease of use of the binary data file where you don't have to worry about it...
21,"Joe Smith", "121 Fooby Lane",
24, "Jane Doe", "4545 Hacienda Street, apt 5",