Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A binary file stores a list of company’s salaries. Each salary is stored as floa

ID: 3821907 • Letter: A

Question

A binary file stores a list of company’s salaries. Each salary is stored as float. Which code fragment below will read the third salary of the file into a variable sal. The file is already opened using the file description fid.

a. fseek(fid, 0, SEEK_SET);

fread(&sal, sizeof(double), 1, fid);

b. fseek(fid, 0, SEEK_END);

rc = ftell(fid);

fseek(fid, rc - 3*sizeof(double), SEEK_END);

fread(&sal, sizeof(double), 1, fid);

c. fseek(fid, 0, SEEK_SET);

rc = ftell(fid);

fseek(fid, rc - 2*sizeof(double), SEEK_CUR);

fread(&sal, sizeof(double), 1, fid);

d. fseek(fid, 0, SEEK_SET);

fseek(fid, 2*sizeof(double), SEEK_CUR);

fread(&sal, sizeof(double), 1, fid);

e. None of the above

Explanation / Answer

Answer:-

C

fseek(fid, 0, SEEK_SET);

rc = ftell(fid);

fseek(fid, rc - 2*sizeof(double), SEEK_CUR);

fread(&sal, sizeof(double), 1, fid);

This will help to read the third salary of the file into a variable sal.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote