C - Files - Discussion

You Are Here :: Home > C > Files - Discussion

 



Q.

What will be the output of the program ?

#include
int main()
{
FILE *fs, *ft;
char c[10];
fs = fopen("source.txt", "r");
c[0] = getc(fs);
fseek(fs, 0, SEEK_END);
fseek(fs, -3L, SEEK_CUR);
fgets(c, 5, fs);
puts(c);
return 0;
}

A. things B. thing
C. ngs D. Error in fseek();

Answer: Option C
Explaination:

The file source.txt contains "do good things".SEEK_END moves the file pointer to the end of the file.(-3L, SEEK_CUR) moves the file pointer backward by 3 characters.c, 5, fs read the file from the current position of the file pointer.Hence, it contains the last 3 characters of "do good things".Therefore, it prints "ngs".



Discussion

Your Comments Goes here...
NameDiscussion