Question 10
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
FILE *fp = tmpfile();
if (fp == NULL)
return 1;
fputs("Learn by doing", fp);
fseek(fp, -5L, SEEK_END);
char word[8];
fscanf(fp, "%7s", word);
printf("%s %ld\n", word, ftell(fp));
fclose(fp);
return 0;
}
- A doing 14 Correct
- B doing 9
- C by 8
- D Learn 5
Correct Answer: Option A
The text is 14 bytes long. Five bytes before the end is "doing"; after reading it the position is at the end, 14.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!