Diagnosing a misplaced record update

A file inventory.dat holds 20 fixed-length binary records. To replace the record with index 5, a program calls fopen("inventory.dat", "a+b"), then fseek(fp, 5 * (long)sizeof rec, SEEK_SET), which returns 0, then fwrite(&rec, sizeof rec, 1, fp), which returns 1, and finally fclose(fp). Afterwards the file holds 21 records: the new data is the last record, and record 5 is unchanged. Which explanation of this behaviour is correct?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Block Files and Random Files Questions: