Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getc(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                                 getc(3C)



        _________________________________________________________________
        getc                                                        macro
        Read a single character from an input stream.
        _________________________________________________________________


        Calling Sequence

        #include <stdio.h>

        FILE *fp;
        int c;
        c = getc(fp);


          where   c = next character, or -1 if an error or end of file
                  occurred.
                  fp is a pointer to a FILE stream.



        Description

        The getc macro reads a single character from a file you specify.
        Since getc is a macro, it produces more in-line code than the
        corresponding call to fgetc, but the code executes faster.  Since
        it is evaluated more than once, fp must not cause side effects.
        You cannot pass getc as a parameter to a function or take its
        address since it is a macro and not a function.  Use fgetc in
        those cases instead.

        If you define the macro _NEXPAND, your C program will call the
        library functions fgetc and fputc instead of the stdio.h macros
        getc and putc.  This allows you to set a breakpoint at the
        routine while debugging.


        Returns

        The getc macro returns a character, or -1 if it reaches the end
        of file or if an error occurs.


        Related Functions

        See also the getchar and putc macros, and the fgetc function.


        Example

        /* Program test for the getc() macro   */



        DG/UX 4.00                                                 Page 1
               Licensed material--property of copyright holder(s)





                                                                 getc(3C)



        #include <stdio.h>
        #define EOF  -1

        FILE   *fp, *fopen();
        int     c;

        main(argc, argv)
        int    argc;
        char  *argv[];
        {
            fp = fopen(argv[1], "r");
            while((c = getc(fp)) != EOF)
                putchar(c);
        }

        A call to the program test with the valid filename input_str,
        which contains

        This is a test input file.

        yields the following at the terminal:

        This is a test input file.































        DG/UX 4.00                                                 Page 2
               Licensed material--property of copyright holder(s)



Typewritten Software • bear@typewritten.org • Edmonds, WA 98026