Ask Question
10 May, 16:04

What function can be used to detect when the end of an input file has been reached?

+2
Answers (1)
  1. 10 May, 19:47
    0
    getc () or feof () in c/c++.

    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

    int main ()

    {

    FILE * f = fopen ("sample. txt", "r");

    int c = getc (f);

    while (c! = EOF)

    {

    putchar (ch);

    ch = getc (f);

    }

    if (feof (f))

    printf ("/n File has ended.");

    else

    printf ("/n Reading not happened.");

    fclose (f);

    getchar ();

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What function can be used to detect when the end of an input file has been reached? ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers