Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

fopen(3S)

fclose(3S)

getc(3S)

puts(3S)

printf(3S)

fread(3S)

PUTC(3S)  —  STANDARD I/O LIBRARY

NAME

putc, putchar, fputc, putw − put character or word on a stream

SYNOPSIS

#include <stdio.h>

int putc(c, stream)
char c;
FILE ∗stream;

putchar(c)

fputc(c, stream)
FILE ∗stream;

putw(w, stream)
FILE ∗stream;

DESCRIPTION

putc writes the character c onto the named output stream (at the position where the file pointer, if defined, is pointing).  It returns the character written. 

putchar(c) is defined as putc(c, stdout).  putc and putchar are macros. 

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

putw writes the C int (word) w to the output 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.  It returns the integer written.  putw neither assumes nor causes special alignment in the file. 

Output streams are by default buffered if the output refers to a file and line-buffered if the output refers to a terminal.  When an output stream is unbuffered, information is queued for writing on the destination file or terminal as soon as written; when it is buffered, many characters are saved up and written as a block.  When it 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).  setbuf(3S), setbuffer(3S), or setvbuf(3S) may be used to change the stream’s buffering strategy.

SEE ALSO

fopen(3S), fclose(3S), getc(3S), puts(3S), printf(3S), fread(3S)

DIAGNOSTICS

On success, these functions each return the value they have written.  On error, these functions return the constant EOF Because EOF is a valid integer, ferror(3S) should be used to detect putw errors. 

BUGS

Because it is implemented as a macro, putc treats a stream argument with side effects improperly.  In particular, putc(c, ∗f++); doesn’t work sensibly.  fputc should be used instead. 

Errors can occur long after the call to putc.

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. 

Sun Release 3.2  —  Last change: 15 April 1986

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