Consider the following C code snippet: #include <stdio.h> int main() { FILE…
PYQ IBPS SO CRP SPL-XIII (2023)
Consider the following C code snippet:
#include <stdio.h>
int main() {
FILE *file = fopen("example.txt", "r");
if (file == NULL) {
printf("Error opening file.\n");
return 1;
}
int ch;
while ((ch = fgetc(file)) != EOF) {
putchar(ch);
}
if (feof(file)) {
printf("\nEnd of file reached.\n");
}
fclose(file);
return 0;
}What is the purpose of the feof(file) function call in this program?
- A.
To read the next character from the file stream
- B.
To determine whether the end-of-file indicator for the file stream has been set
- C.
To close the file after all characters are read
- D.
To move the file pointer to the beginning of the file
- E.
To open the file in read mode
Attempted by 23 students.
Sign up free to check your answer
Sign up freeLoading lesson…

