Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ putc(3) — AIX/RT 2.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fclose, fflush

feof, ferror, clearerr, fileno

fopen, freopen, fdopen

fread, fwrite

getc, fgetc, getchar, getw

printf, fprintf, sprintf, NLprintf, NLfprintf, NLsprintf

puts, fputs

setbuf, setvbuf

standard i/o library

     putc, putchar, fputc, putw

Purpose

     Writes a character or a word to a stream.

Library

     Standard I/O Library (libc.a)

Syntax

     #include <stdio.h>

     int putc(c, stream)                       int fputc(c, stream)
     char c;                                   char c;
     FILE *stream;                             FILE *stream;

     int putchar(c)                            int putw(w, stream)
     char c;                                   int w;
                                               FILE *stream;
     Description

     The putc macro writes the character c to the output spec-
     ified by the stream  parameter.  The character is written
     at the  position at which  the file pointer  is currently
     pointing, if defined.

     The putchar  macro is the  same as the putc  macro except
     that putchar writes to the standard output.

     The fputc subroutine works the same as putc, but fputc is
     a  true subroutine  rather than  a macro.   It runs  more
     slowly than putc, but takes less space per invocation.

     Because putc is implemented as  a macro, it treats incor-
     rectly  a stream  parameter  with side  effects, such  as
     "putc(c,  *f++)".  For  such  cases,  use fputc  instead.
     Also, use  fputc whenever you  need to pass a  pointer to
     this subroutine as a parameter to another subroutine.

     The putw  subroutine writes  the word (int)  specified by
     the w  parameter to  the output  specified by  the stream
     parameter.  The word is written  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 subroutine  does not assume  or cause
     special alignment of the data in the file.

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

     With  the exception  of  stderr, output  streams are,  by
     default,  buffered  if  they  refer to  files,  or  line-
     buffered if they refer  to terminals.  The standard error
     output  stream, stderr,  is  unbuffered  by default,  but
     using the freopen subroutine causes it to become buffered
     or line-buffered.   Use the  setbuf subroutine  to change
     the stream's buffering strategy.

     When  an  output  stream is  unbuffered,  information  is
     queued for writing on the destination file or terminal as
     soon as  it is written.    When an output stream  is buf-
     fered, many characters are saved  and written as a block.
     When  an output  stream  is line-buffered,  each line  of
     output is queued for  writing on the destination terminal
     as soon as  the line is completed (that is,  as soon as a
     new-line  character  is  written  or  terminal  input  is
     requested).

     Return Value

     Upon successful  completion, these functions  each return
     the value  written. If these functions  fail, they return
     the constant  EOF.  They fail  if the stream is  not open
     for  writing,  or  if  the output  file  size  cannot  be
     increased.  Because  EOF is  a valid integer,  you should
     use the ferror subroutine to detect putw errors.

     Related Information

     In this book:  "fclose, fflush," "feof, ferror, clearerr,
     fileno,"  "fopen,  freopen,   fdopen,"  "fread,  fwrite,"
     "getc, fgetc, getchar,  getw," "printf, fprintf, sprintf,
     NLprintf, NLfprintf, NLsprintf,"  "puts, fputs," "setbuf,
     setvbuf," and "standard i/o library."

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