Can anyone tell me how to read variable length fields from a sequential file using fscanf. The fields are delimited by commas.
Fields to be read in are
· Student Number (5 digits)
· Student Name (25 characters max.)
· Curriculum Code (3 characters)
· 8 Class Work Grades (2 characters max., may be : a+, a, a-, b+, b, b-, c+... f)
· 4 Test Grades (3 digits max.)
· Final Exam (3 characters max., [not a mistake!!])
lets assume that the file is set up like thiS:
Thus it is has the requisite fields and is comma delimited. If that's the way the file is set up then I think you would read the entire line into a holding string using fscanf, parse the line into substrings using strtok() with comma as the delimiterm and finally convert the strings containing numeric data into appropriate data type using atoi(), atol(), or atof().
thus to start I would try this:
FILE * pFile;
pFile = fopen("sample.txt", "r");
fscanf(pFile, "%s", buffer);
On a side note, please don't cross post and double post, it's very annoying to open up a new thread and find that it's the one you just answered. Post once and only once, then be patient and the answers will come.
Sorry about the cross post!