Question
1)Write out the file contents for out.txt as produced by the following code. Give specific byte values. How many total bytes will the file contain
1)Write out the file contents for out.txt as produced by the following code. Give specific byte values. How many total bytes will the file contain at the end of execution?
#include
main() {
FILE *fpt;
int x;
fpt=fopen("out.txt","w");
for (x=0; x<15; x+=2)
fprintf(fpt,"%2d ",x);
fclose(fpt);
}
2)Write out the file contents for out2 as produced by the following code. Give specific values to bytes or ranges of bytes. The values of the same variable are being written using fprintf() and then fwrite(). How many bytes are written by each, and which is more efficient?
#include
main() {
FILE *fpt;
struct frog {
float d;
int x;
} henry;
henry.d=12.73;
henry.x=81925;
fpt=fopen("out2","w");
fprintf(fpt,"%7.2f %7d ",henry.d,henry.x);
fwrite(&henry,sizeof(struct frog),1,fpt);
fclose(fpt);
}
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