ffeerrrroorr() -- STDIO Function (libc)

Discover stream status
#iinncclluuddee <ssttddiioo.hh>
iinntt ffeerrrroorr(_f_p) FFIILLEE *_f_p;

ffeerrrroorr() tests the status of the  file stream _f_p. It returns a number other
than  zero if  an error  has occurred  on _f_p. Any  error condition  that it
discovers persists until you either  close the stream or call cclleeaarreerrrr() to
clear it.  For write routines that employ buffers, call fffflluusshh() before you
call ffeerrrroorr(), in case an error occurs on the last block written.

_E_x_a_m_p_l_e
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++;
                }

                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);
}

_S_e_e _A_l_s_o
lliibbcc
ANSI Standard, section 7.9.10.3
POSIX Standard, section 8.1
