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


clearerr

Clear a stream's end-of-file and error status.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


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

Parameters for this facility are:

stream  
FILE *  
A pointer to a FILE stream  

Remarks:

The clearerr() function resets the end-of-file status and error status for stream. The end-of-file status and error status are also reset when a stream is opened.

See Also:

"feof"

"ferror"

"fopen"

"fseek"

"rewind"

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

int main(void)
{
	FILE *f;

	static char name[] = "myfoo";
	char buf[80];

	// create a file for output
	if ( (f = fopen(name, "w")) == NULL) {
		printf("Can't open %s.\n", name);
		exit(1);
	}
	// output text to the file
	fprintf(f, "chair table chest\n");
	fprintf(f, "desk raccoon\n");

	// close the file
	fclose(f);

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


	// read all the text until end-of-file
	for (; feof(f) == 0; fgets(buf, 80, f))
		fputs(buf, stdout);

	printf("feof() for file %s is %d.\n", name, feof(f));
	printf("Clearing end-of-file status. . .\n");
	clearerr(f);
	printf("feof() for file %s is %d.\n", name, feof(f));
	
	// close the file
	fclose(f);

	return 0;
}

Output
chair table chest
desk raccoon
feof() for file myfoo is 256.
Clearing end-of-file status. . .
feof() for file myfoo is 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