putc(3S)putc(3S)NAMEputc(), putchar(), fputc(), putw() - put character or word on a stream
Writes the character
c onto the output stream at the position where the file
pointer, if defined, is pointing. is defined as and are
defined both as macros and as functions.
Same as but is a function rather than a macro, and can therefore
be used as an argument. runs more slowly than but takes
less space per invocation, and its name can be passed as
an argument to a function.
Writes the word (i.e.,
in C) 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. neither assumes nor causes special align‐
ment in the file.
Output streams, with the exception of the standard error stream are by
default buffered if the output refers to a file and line-buffered if
the output refers to a terminal. The standard error output stream, is
by default unbuffered, but use of (see fopen(3S)) causes it to become
buffered or line-buffered. or (see setbuf(3S)) can be used to change
the stream's buffering strategy. put character on a stream.
put character or word on a stream.
After or is applied to a stream, the stream becomes byte-oriented (see
On success, and each return the value they have written. On failure,
they return the constant EOF, set the error indicator for the stream,
and set to indicate the error.
On success, and return 0. Otherwise, a non-zero value is returned, the
error indicator for the stream is set, and is set to indicate the
and fail if, either the stream is unbuffered or stream's buffer needed
to be flushed causing an underlying call to be invoked, and:
[EAGAIN] The flag is set for the file descriptor underly‐
ing stream and the process would be delayed in
the write operation.
[EBADF] The file descriptor underlying stream is not a
valid file descriptor open for writing.
[EFBIG] An attempt was made to write to a file that
exceeds the process's file size limit or the max‐
imum file size (see ulimit(2)).
[EINTR] A signal was caught during the system call.
[EIO] A physical I/O error has occurred, or the process
is in a background process group and is attempt‐
ing to write to its controlling terminal, is set,
the process is neither ignoring nor blocking the
signal, and the process group of the process is
[ENOSPC] There was no free space remaining on the device
containing the file.
[EPIPE] An attempt is made to write to a pipe or FIFO
that is not open for reading by any process. A
signal is also sent to the process.
Additional values can be set by the underlying function (see write(2)).
The and routines are implemented as both library functions and macros.
The macro versions, which are used by default, are defined in To obtain
the library function either use a to remove the macro definition or, if
compiling in ANSI-C mode, enclose the function name in parentheses or
use the function address. The following example illustrates each of
Line buffering may cause confusion or malfunctioning of programs that
use standard I/O routines but use themselves to read from standard
input. When a large amount of computation is done after printing part
of a line on an output terminal, it is necessary to (see fclose(3S))
the standard output before beginning the computation.
The macro version of incorrectly treats the argument stream with side
effects. In particular, the following call may not work as expected:
The function version of or should be used instead.
Because of possible differences in word length and byte ordering, files
written using are machine-dependent, and may not be readable by on a
is an obsolescent interface supported only for compatibility with
existing DCE applications. New multithreaded applications should use
If is defined, the locked versions of the library functions for and are
used by default.
SEE ALSOfclose(3S), ferror(3S), flockfile(3S), fopen(3S), getc(3S), fread(3S),
printf(3S), puts(3S), setbuf(3S), orientation(5), thread_safety(5).