Tracing the file position through a record update

A binary file holds exactly 20 fixed-length records of 48 bytes each, so it is 960 bytes long. On a POSIX system, a program opens it with mode "r+b", so the position starts at byte 0, and buf is a 144-byte array. The program then makes these seven calls in order:


C
fseek(fp, 240L, SEEK_SET);   /* call 1 */
fread(buf, 48, 1, fp);       /* call 2 */
fseek(fp, -48L, SEEK_CUR);   /* call 3 */
fwrite(buf, 48, 1, fp);      /* call 4 */
fseek(fp, -96L, SEEK_END);   /* call 5 */
fread(buf, 48, 3, fp);       /* call 6 */
fseek(fp, 48L, SEEK_CUR);    /* call 7 */


Every call succeeds as far as the file allows. For each call, enter the value ftell(fp) would return immediately after it, in bytes from the start of the file, and the value the call itself returns. Give whole numbers.

CallPosition after call (bytes)Return value
Call 1
Call 2
Call 3
Call 4
Call 5
Call 6
Call 7

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: