|
|
coherent
ferror() STDIO Macro ferror()
Discover stream status
#include <stdio.h>
iinntt ffeerrrroorr(_f_p) FFIILLEE *_f_p;
ferror is a macro that tests the status of the file stream fp.
It returns a number other than zero if an error has occurred on
fp. Any error condition that is discovered will persist either
until the stream is closed or until clearerr is used to clear it.
For write routines that employ buffers, fflush should be called
before ferror, in case an error occurs on the last block written.
***** Example *****
This example reads a word from one file and writes it into
another.
#include <stdio.h>
main()
{
FILE *fpin, *fpout;
int inerr = 0;
int outerr = 0;
int word;
char infile[20], outfile[20];
printf("Name data file you wish to copy:\n");
gets(infile);
printf("Name new file:\n");
gets(outfile);
if ((fpin = fopen(infile, "r")) != NULL) {
if ((fpout = fopen(outfile, "w")) != NULL) {
for (;;) {
word = fgetw(fpin);
if (ferror(fpin)) {
clearerr(fpin);
inerr++;
}
COHERENT Lexicon Page 1
ferror() STDIO Macro ferror()
if (feof(fpin))
break;
fputw(word, fpout);
if (ferror(fpout)) {
clearerr(fpout);
outerr++;
}
}
} else {
printf
("Cannot open output file %s\n",
outfile);
exit(1);
}
} else {
printf("Cannot open input file %s\n", infile);
exit(1);
}
printf("%d - read error(s) %d - write error(s)\n",
inerr, outerr);
exit(0);
}
***** See Also *****
STDIO
COHERENT Lexicon Page 2
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.