I want to read some data from a file into a data structure, how can I use the scanf function and do error checking?
For example -
fp = fopen(filename, "r");
Entry entry = new Entry();
if (fp == NULL)
fprintf(stderr, "Error: Unable to open file %s\n\n", string);
//while( (ch=getc(fptr)) != EOF )
***Normally I would try to get each character and see if I reach the end of file, but if I want to use fscanf, how should I detect the eof?***
***Also, what about if there is error in the input file? For example, If I am expecting a pattern like john, smith, 1/1/2000, firstname.lastname@example.org
***I would like to know how I can detect fields missing or corrupted error with scanf?
fscanf(fp, "%s,%s,%s,%s", entry.firstName, entry.lastName,
Look forward to hear from you