Check the error status of a stream.
Compatibility:This function is compatible with the following targets:
|
|
#include <stdio.h>
int ferror (FILE *stream);Parameters:
Parameters for this facility are:
NOTE
#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