ffggeettcc() -- STDIO Function (libc)

Read character from stream
#iinncclluuddee <ssttddiioo.hh>
iinntt ffggeettcc(_f_p) FFIILLEE *_f_p;

ffggeettcc() reads  characters from the input stream _f_p.  In general, it behaves
the same as the macro ggeettcc(): it runs more slowly than ggeettcc(), but yields a
smaller object module when compiled.

_E_x_a_m_p_l_e
This example counts the number of lines and ``sentences'' in a file.

#include <stdio.h>

main()
{
    FILE *fp;
    int filename[20];
    int ch;
    int nlines = 0;
    int nsents = 0;

    printf("Enter file to test: ");
    gets(filename);

    if ((fp = fopen(filename,"r")) == NULL) {
        printf("Cannot open file %s.\n", filename);
        exit(1);
    }

    while ((ch = fgetc(fp)) != EOF) {
        if (ch == '\n')
            ++nlines;

        else if (ch == '.' || ch == '!' || ch == '?') {
            if ((ch = fgetc(fp)) != '.')
                 ++nsents;

            else
                while((ch=fgetc(fp)) == '.')
                    ;
            ungetc(ch, fp);
        }
    }

    printf("%d line(s), %d sentence(s).\n",
        nlines, nsents);
}

_S_e_e _A_l_s_o
ggeettcc(), lliibbcc
ANSI Standard, section 7.9.7.1
POSIX Standard, section 8.1

_D_i_a_g_n_o_s_t_i_c_s
ffggeettcc() returns EOF at end of file or on error.
