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?

  1. A.

    To read the next character from the file stream

  2. B.

    To determine whether the end-of-file indicator for the file stream has been set

  3. C.

    To close the file after all characters are read

  4. D.

    To move the file pointer to the beginning of the file

  5. E.

    To open the file in read mode

Attempted by 23 students.

Sign up free to check your answer

Sign up free

Explore the full course: Ibps So It Mains

Loading lesson…