putc(3S) STANDARD I/O FUNCTIONS 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 out-
put 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 position-
ing 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 argu-
ment to a function.
putw writes the word (i.e., integer) w to the output stream
(where the file pointer, if defined, is pointing). The size
of a word is the size of an integer and varies from machine
to machine. putw neither assumes nor causes special align-
ment in the file.
SEE ALSO
exit(2), lseek(2), write(2), abort(3C), fclose(3S),
ferror(3S), fopen(3S), fread(3S), printf(3S), puts(3S),
setbuf(3S), stdio(3S).
DIAGNOSTICS
On success, these functions (with the exception of putw)
each return the value they have written. putw returns fer-
ror (stream). On failure, they return the constant EOF.
This result will occur, for example, if the file stream is
not open for writing or if the output file cannot grow.
NOTES
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
Last change: C Programming Language Utilities 1
putc(3S) STANDARD I/O FUNCTIONS putc(3S)
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 (e.g.,
#undef putc).
Last change: C Programming Language Utilities 2