Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ putc(3C) — DG/UX 4.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought



                                                                 putc(3C)



        _________________________________________________________________
        putc                                                        macro
        Write a character to a given file.
        _________________________________________________________________


        Calling Sequence

        #include <stdio.h>
        FILE *fp;
        char nextchar;
        putc(nextchar, fp);


          where   nextchar is the character to write out.
                  fp is a pointer to a FILE stream.



        Description

        The putc macro writes a character to a file you specify.  Since
        this is a macro, the code is expanded in line.  The code is
        faster than a function call such as fputc, though it takes a few
        more instructions and more code space.  The fp pointer must not
        have any side effects.

        You cannot pass putc as a parameter to a function or take its
        address, since it is a macro and not a function.  Use fputc
        instead in these cases.

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

        See the "I/O Functions and Macros" section of Chapter 1 for
        buffering information on the putc macro.


        Returns

        The putc macro returns the character; it returns -1 if an error
        occurs.


        Related Functions

        See also the getc and putchar macros, and the fputc and puts
        functions.




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





                                                                 putc(3C)



        Example

        /* Program test for the putc() macro on strings */

        #include <stdio.h>

        FILE   *fpi, *fpo, *fopen();
        int     c, i = 0;

        main(argc, argv)
        int     argc;
        char   *argv[];
        {
            fpi = fopen(argv[1], "r");
            fpo = fopen(argv[2], "w");
            while ((c = getc(fpi)) != EOF) {
                putc(c, fpo);
                i++;
            }
            printf("Number of bytes copied from %s to %s = %d",
            argv[1], argv[2], i);
        }

        A call to the program test with the filenames in_char and
        out_char, when in_char contains

        abcdefghij

        generates the output

        Number of bytes copied from in_char to out_char = 10























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



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