Question
A binary file stores a list of companys salaries. Each salary is stored as float. Which code fragment below will read the third salary of
A binary file stores a list of companys 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started