ffggeettss() -- STDIO Function (libc)

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

ffggeettss() reads characters from the stream  _f_p into string _s until either _n-1
characters have been read, or a  newline or EOF is encountered.  It retains
the newline,  if any,  and appends a  null character at  the end of  of the
string.  ffggeettss()  returns the argument  _s if any characters  were read, and
NULL if none were read.

_E_x_a_m_p_l_e
This example looks for the pattern given by aarrggvv[11] in standard input or in
file  aarrggvv[22].  It  demonstrates  the  functions  ppnnmmaattcchh(),  ffggeettss(),  and
ffrreeooppeenn().

#include <stdio.h>
#define MAXLINE 128
char buf[MAXLINE];

void fatal(s) char *s;
{
    fprintf(stderr, "pnmatch: %s\n", s);
    exit(1);
}

main(argc, argv)
int argc; char *argv[];
{
    if (argc != 2 && argc != 3)
        fatal("Usage: pnmatch pattern [ file ]");

    if (argc==3 && freopen(argv[2], "r", stdin)==NULL)
        fatal("cannot open input file");

    while (fgets(buf, MAXLINE, stdin) != NULL) {
        if (pnmatch(buf, argv[1], 1))
            printf("%s", buf);
    }

    if (!feof(stdin))
        fatal("read error");
    exit(0);
}

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

_D_i_a_g_n_o_s_t_i_c_s
ffggeettss()  returns NULL  if an  error occurs,  or if EEOOFF  is seen  before any
characters are read.
