Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

putc(3)

fclose(3)

ferror(3)

fopen(3)

fread(3)

printf(3)

puts(3)

setbuf(3)

stdio(3)



  putc(3)                             CLIX                             putc(3)



  NAME

    putc, putchar, fputc, putw - Puts character or word on a stream

  LIBRARY

    Standard C Library (libc.a)

  SYNOPSIS

    #include <stdio.h>

    int putc(
      int c ,
      FILE *stream );

    int putchar(
      int c );

    int fputc(
      int c ,
      FILE *stream );

    int putw(
      int w ,
      FILE *stream );

  PARAMETERS

    c        A character

    w        A word

    stream   A stream

  DESCRIPTION

    The putc() function writes the character c onto the output stream (at the
    position where the file pointer, if defined, is pointing).  The putchar()
    function is defined as

    putc(c, stdout)

    The putc() and putchar() functions are macros.

    The fputc() function behaves like putc(), but is a function rather than a
    macro.  The fputc() function runs more slowly than putc(), but it takes
    less space per invocation and its name can be passed as an argument to a
    function.

    The putw() function writes the word (that is, integer) w to the output



  2/94 - Intergraph Corporation                                              1






  putc(3)                             CLIX                             putc(3)



    stream (at the position at which the file pointer, if defined, is
    pointing).  The size of a word is the size of an integer and varies from
    machine to machine.  The putw() neither assumes nor causes special
    alignment in the file.

    Because it is implemented as a macro, putc() evaluates a stream argument
    more than once.  In particular, putc(c, *f++); doesn't work sensibly.
    fputc() should be used instead.

    Because of possible differences in word length and byte ordering, files
    written using putw() are machine-dependent, and may not be read using
    getw() on a different processor.

  EXAMPLES

    A possible implementation of the cp command uses putc() to copy to source
    file and putchar() to echo it to the screen:

    #include <stdio.h>

    main(argc,argv)
    int argc;
    char *argv[];
    {
         if(argc < 2)
              printf("This command requires two arguments.\n");
         else {
              FILE *infile;
              FILE *outfile;
              int letter;

              infile = fopen(argv[1], "r");
              outfile = fopen(argv[2], "w");

              while((letter = getc(infile)) != EOF) {
                   putc(letter, outfile);
                   putchar(letter);
              }
         }
    }


  RETURN VALUES

    On success, these functions (with the exception of putw()) each return the
    value they have written.  [putw() returns ferror (stream)].  On failure,
    they return the constant EOF.  This will occur if the file stream is not
    open for writing or if the output file cannot grow.  Because EOF is a
    valid integer, ferror() should be used to detect putw() errors.

  RELATED INFORMATION



  2                                              Intergraph Corporation - 2/94






  putc(3)                             CLIX                             putc(3)



    Functions:  fclose(3), ferror(3), fopen(3), fread(3), printf(3), puts(3),
    setbuf(3), stdio(3)




















































  2/94 - Intergraph Corporation                                              3




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