Answer:
getc() or feof() in c/c++.
Step-by-step explanation:
getc() returns EOF(End of File) when the end of the file reached is reached but it is not efficient because it also return EOF when it fails.
feof() returns non-zero value when the EOF is reached otherwise it return 0.So feof() is an efficient method to read a file.
For example:-
#include <stdio.h>
int main()
{
FILE *f = fopen("sample.txt", "r");
int c = getc(f);
while (c!= EOF)
{
putchar(ch);
ch = getc(f);
}
if (feof(f))
printf("\\ File has ended.");
else
printf("\\ Reading not happened.");
fclose(f);
getchar();
return 0;
}