Ask Question
11 February, 18:38

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

+3
Answers (1)
  1. 11 February, 22:03
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers