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 flo

ID: 3821703 • 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

d. fseek(fid,0,SEEK_SET); // 0 displacement is the beginning of the file

fseek(fid,2*sizeof(double),SEEK_CUR); // 2 doubles are skipped ,positive displacement for forward direction

fread(&sal,sizeof(double),1,fid); // 3 salary of file is assigned to 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