C Standard Libraries C++

feof()

Declaration

int feof(FILE* qpStream);

Description

This function tests "qpStream" for an end-of-file condition signalled by an attempt to read beyond the end of the file. The function returns 0 to signal that no attempt has been made to read beyond the end of the file and a non-zero value otherwise.

Input File

feof() Input File

Example

#include <cstdio>

int main()
{
    char* cpFileName = "XoaX.txt";
    FILE* qpFile = fopen(cpFileName, "r" );

    // Check that the file was opened
    if (!qpFile) {
        printf("Could not open %s for reading \n",  cpFileName);
        return 1;
    }

    char caReadBuffer[20];
    int iIndex = 0;
    // Get characters until the we hit the end of the file.
    while (!feof(qpFile)) {
        caReadBuffer[iIndex] = (char)getc(qpFile);
        ++iIndex;
    }
    // Add a null terminator
    caReadBuffer[iIndex] = 0;
    // Output the read contents of the file
    printf("Text of %s:\n%s\n", cpFileName, caReadBuffer);

    fclose(qpFile);

    return 0;
}

Output

feof() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.