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


ferror

Check the error 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 ferror (FILE *stream);
Parameters:

Parameters for this facility are:

stream  
FILE *  
A pointer to a FILE stream  

Remarks:

The ferror() function returns the error status of the last read or write operation on stream. The function does not reset its error status.


NOTE

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

ferror() returns a nonzero value if stream's error status is on, and returns zero if stream's error status is off.

See Also:

"clearerr"

"feof"

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

int main(void)
{
	FILE *f;
	char filename[80], buf[80];
	int ln = 0;
	
	// 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 the file one line at a time until end-of-file
	do {
		fgets(buf, 80, f);
		printf("Status for line %d: %d.\n", ln++, ferror(f));
	} while (feof(f) == 0);
	
	// close the file
	fclose(f);

	return 0;
}

Output:
Enter a filename to read.
itwerks
Status for line 0: 0.
Status for line 1: 0.
Status for line 2: 0.


[ 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