File:  [MW Coherent from dump] / coherent / a / usr / man / ALL / freopen
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



freopen()                 STDIO Function                freopen()




Open file stream for standard I/O

#iinncclluuddee <ssttddiioo.hh>
FFIILLEE *ffrreeooppeenn (_n_a_m_e, _t_y_p_e, _f_p)
cchhaarr *_n_a_m_e, *_t_y_p_e; FFIILLEE *_f_p;

ffrreeooppeenn  reinitializes the  file stream fp.   It closes  the file
currently associated with it, opens or creates the file name, and
returns  a  pointer  to the  structure  for  use  by other  STDIO
routines.  name names a file.

_t_y_p_e is a  string that consists of one or  more of the characters
``rrwwaa'' (for, respectively, read, write, and append)  to indicate
the mode of the stream.  For further discussion of the type vari-
able, see  the entry for fopen.  freopen  differs from fopen only
in  that  fp  specifies  the  stream  to  be  used.   Any  stream
previously associated  with fp is  closed by ffcclloossee.   ffrreeooppeenn is
usually used to change the meaning of ssttddiinn, ssttddoouutt, or ssttddeerrrr.

***** Example *****

This example,  called mmaattcchh.cc, looks  in aarrggvv[22] for  the pattern
given by  aarrggvv[11].  If the  pattern is found, the  line that con-
tains the pattern is written into the file aarrggvv[33] or to ssttddoouutt.


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



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



main(argc,argv)
int argc; char *argv[];
{
        FILE *fpin, *fpout;



        if (argc != 3 && argc != 4)
                fatal("Usage: match pattern infile [outfile]");
        if ((fpin = fopen(argv[2], "r")) == NULL)
                fatal("Cannot open input file");




COHERENT Lexicon                                           Page 1




freopen()                 STDIO Function                freopen()





        fpout = stdout;
        if (argc == 4)
                if ((fpout = freopen(argv[3], "w", stdout)) == NULL)
                        fatal("Cannot open output file");



        while (fgets(buffer, MAXLINE, fpin) != NULL) {
                if (pnmatch(buffer, argv[1], 1))
                        fputs(buffer, stdout);
        }
        exit(0);
}


***** See Also *****

fopen(), STDIO

***** Diagnostics *****

freopen returns  NULL if  the type string  is nonsense or  if the
file cannot be opened.  Currently, only 20 FFIILLEE structures can be
allocated per program, including ssttddiinn, ssttddoouutt, and ssttddeerrrr.































COHERENT Lexicon                                           Page 2



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.