[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


feof

Check the end-of-file status of a stream.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stdio.h>
int feof(FILE *stream);
Parameters:

Parameters for this facility are:

stream  
FILE *  
A pointer to a FILE stream  

Remarks:

The feof() function checks the end-of-file status of the last read operation on stream. The function does not reset the end-of-file status.


NOTE

On embedded/ RTOS systems this function only is implemented for stdin, stdout and stderr files.
Return:

feof() returns a nonzero value if the stream is at the end-of-file and return zero if the stream is not at the end-of-file.

See Also:

"clearerr"

"ferror"

Example of feof() usage.:
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	FILE *f;
	static char filename[80], buf[80] = "";
	
	// get a filename from the user
	printf("Enter a filename to read.\n");
	gets(filename);

	// open the file for input
	if (( f = fopen(filename, "r")) == NULL) {
		printf("Can't open %s.\n", filename);
		exit(1);
	}

	// read text lines from the file until
	// feof() indicates the end-of-file
	for (; feof(f) == 0 ; fgets(buf, 80, f) )
		printf(buf);

	// close the file
	fclose(f);

	return 0;
}

Output:
Enter a filename to read.
itwerks
The quick brown fox
jumped over the moon.


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000