Correct option is B
The feof(file) function is used to check whether the End-Of-File (EOF) indicator has been set for the specified file stream.
In the given program, characters are continuously read using fgetc() until EOF is encountered. After the loop terminates, feof(file) verifies whether the loop ended because the file reached its end. If true, the message "End of file reached." is displayed.
Therefore, the purpose of feof(file) is to determine whether the end of the file has been reached.
Important Key Points:
- feof() checks the EOF indicator associated with a file stream.
- It returns a non-zero value if the end of file has been reached.
- fgetc() reads characters one by one from the file.
- feof() is generally checked after a file-reading operation fails or reaches EOF.
Knowledge Booster:
- (a) To read the next character from the file stream: Incorrect because character reading is performed by fgetc(), not feof().
- (c) To close the file after all characters are read: Incorrect because file closing is handled using fclose().
- (d) To move the file pointer to the beginning of the file: Incorrect because repositioning the file pointer is done using functions like rewind() or fseek().
- (e) To open the file in read mode: Incorrect because opening a file in read mode is performed using fopen("example.txt", "r").
