Ask Question

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

+4
Answers (1)
  1. 27 November, 22:39
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers