Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

write(2)

intro(3)

fclose(3S)

ferror(3S)

fopen(3S)

printf(3S)

puts(3S)

setbuf(3S)

stdio(3S)

putc(3S)

NAME

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

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);

DESCRIPTION

putc() writes c (converted to an unsigned char) onto the output stream (see intro(3)) at the position where the file pointer (if defined) is pointing, and advances the file pointer appropriately.  If the file cannot support positioning requests, or stream was opened with append mode, the character is appended to the output stream.  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 standard I/O output stream (at the position of the file pointer, if defined).  The size of a word is the size of an integer and varies from machine to machine.  putw() neither assumes nor causes special alignment in the file. 

RETURN VALUES

On success, putc(), fputc(), and putchar() return the value that was written.  On error, those functions return the constant EOF.  putw() returns ferror(stream), so that it returns 0 on success and 1 on failure. 

Failure will occur, for example, if the file stream is not open for writing or if the output file cannot grow. 

SEE ALSO

write(2), intro(3), fclose(3S), ferror(3S), fopen(3S), printf(3S), puts(3S), setbuf(3S), stdio(3S)

NOTES

Because it is implemented as a macro, putc() evaluates a stream argument more than once.  In particular, putc(c, ∗f++); does not 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. 

Functions exist for all the above defined macros.  To get the function form, the macro name must be undefined (for example, #undef putc). 

SunOS 5.1/SPARC  —  Last change: 28 Oct 1991

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