In simple statements - you want to read the last record of the file.
Assuming a file with at least one record---------------
fread() reads from the file pointer postion on further into the file. NEVER backwards.Code:#define ZERO 0 int result; result = fseek(fp,ZERO,SEEK_END); // file pointer is on the last record, let's see where that is result = ftell(fp); result -= sizeof(struct data); // calculate one back result = fseek(fp,result,SEEK_SET); // file pointer is now on first byte of last record
Okay?




Reply With Quote