feof()

QNX SDP8.0C Library ReferenceAPIDeveloper

Test a stream's end-of-file flag

Synopsis:

#include <stdio.h>

int feof( FILE* fp );

Arguments:

fp
The stream you want to test.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The feof() function tests the end-of-file flag for the stream specified by fp.

Because the end-of-file flag is set when an input operation attempts to read past the end-of-file, the feof() function detects the end-of-file only after an attempt is made to read beyond the end-of-file. Thus, if a file contains 10 lines, the feof() won't detect the end-of-file after the tenth line is read; it will detect the end-of-file on the next read operation.

It does not change the value of errno if the stream is valid.

Returns:

0 if the end-of-file flag isn't set, or nonzero if the end-of-file flag is set.

Examples:

#include <stdio.h>
#include <stdlib.h>

void process_record( char *buf )
{
    printf( "%s\n", buf );
}

int main( void )
{
    FILE *fp;
    char buffer[100];

    fp = fopen( "file", "r" );
    fgets( buffer, sizeof( buffer ), fp );
    while( ! feof( fp ) ) {
        process_record( buffer );
        fgets( buffer, sizeof( buffer ), fp );
    }
    fclose( fp );
    
    return EXIT_SUCCESS;
}

Classification:

ANSI, POSIX 1003.1

Safety:
Cancellation pointNo
Signal handlerNo
ThreadYes
Page updated: