File:  [MW Coherent from dump] / coherent / a / usr / man / ALL / getc
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



getc()                     STDIO Macro                     getc()




Read character from file stream

#include <stdio.h>
iinntt ggeettcc(_f_p) FFIILLEE *_f_p;

getc is a  macro that reads a character from  the file stream _f_p,
and returns an int.

***** Example *****

The following  example creates a  simple copy utility.   It opens
the first file named on  the command line and copies its contents
into the second file named on the command line.


#include <stdio.h>



void fatal(string)
char *string;
{
        printf("%s\n", string);
        exit (1);
}



main(argc, argv)
int argc; char *argv[];
{
        int foo;
        FILE *source, *dest;



        if (--argc != 2)
                fatal("Usage: copy [source][destination]");



        if ((source = fopen(argv[1], "r")) == NULL)
                fatal("Cannot open source file");
        if ((dest = fopen(argv[2], "w")) == NULL)
                fatal("Cannot open destination file");



        while ((foo = getc(source)) != EOF)
                putc(foo, dest);
}





COHERENT Lexicon                                           Page 1




getc()                     STDIO Macro                     getc()



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

fgetc(), getchar(), putc(), STDIO

***** Diagnostics *****

getc returns EOF at end of file or on read fatal.

***** Notes *****

Because  getc is  a macro, arguments  with side  effects probably
will  not work  as  expected.  Also,  because getc  is a  complex
macro, its use in expressions of too great a complexity may cause
unforeseen  difficulties.  Use  of the  function fgetc  may avoid
this.










































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.