Writing a record beyond the end of a random file

A random-access file of fixed-length 64-byte records currently holds records 0 to 11, so it is 768 bytes long. On a POSIX system, a program opens it with mode "r+b" and stores a new record at zero-based index 30:


C
fseek(fp, 30L * 64, SEEK_SET);
fwrite(rec, 64, 1, fp);


Both calls succeed. The program then seeks to the start of record 20 and calls fread(buf, 64, 1, fp).


Give whole numbers for: the new file size in bytes, the number of 64-byte record slots between the old end of file and the new record that were never written, the total size of that gap in bytes, and the value returned by the final fread.

Your answers

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: