PUTC(3S) SysV PUTC(3S)
NAME
putc, putchar, fputc, putw - put character or word on a stream
SYNOPSIS
#include <stdio.h>
int putc (c, stream)
int c;
FILE *stream;
int putchar (c)
int c;
int fputc (c, stream)
int c;
FILE *stream;
int putw (w, stream)
int w;
FILE *stream;
DESCRIPTION
The putc macro writes the character c to the output specified by the
stream argument. The character is written at the position at which the
file pointer is currently pointing, if defined.
The agruments are defined as follows:
stream
Points to the file structure of an open file.
c Specifies the character to be written.
The putchar macro is the same as the putc() macro except that putchar
writes to the standard output.
The fputc function works the same as the putc() macro, but fputc is a
true function rather than a macro. It runs more slowly than putc, but
takes less space per invocation.
Because putc is implemented as a macro, it incorrectly treats a stream
argument with side effects, such as putc(c, *f++). For such cases, use
the fputc function. Also, use fputc when you need to pass a pointer to
this function as a argument to another function.
The putw function writes the word (int) specified by the w argument to
the output specified by the stream argument. 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 function 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 function are machine-dependent, and may not be
readable using the getw function on a different processor. The st_ctime
and st_mtime fields of the file are marked for update between the
successful execution of the putc, putw, putchar, or fputc function, and
the next successful completion of a call to the fflush or fclose function
on the same stream, or a call to the exit (2) or abort(3C) function.
DIAGNOSTICS
Upon successful completion, these functions each return the value
written. If these functions fail, they return the constant EOF. They fail
if the stream argument is not open for writing, or if the output file
size cannot be increased. Because the EOF value is a valid integer, you
should use the ferror function to detect the putw argument errors.
ERRORS
The putc, putw, putchar, and fputc functions fail if either the stream is
unbuffered, or the stream's buffer needed to be flushed and the function
call caused an underlying write or lseek to be invoked. In addition, the
putc, putw, putchar, or fputc fail if
[EAGAIN] The O_NONBLOCK flag is set for the file descriptor
underlying 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' file size limit or the maximum file size.
[EINTR] The read operation was interrupted by a signal which was
caught, and no data was transferred.
[EIO] The implementation supports job control, the process is a
member of a background process group attempting to write
to its controlling terminal, TOSTOP is set, the process is
neither ignoring nor blocking SIGTTOU and the process
group of the process is orphaned.
[ENOSPC] There was no free space remaining on the device containing
the file.
[EPIPE] An attempt was made to write to a pipe or FIFO that is not
open for reading by any process. A SIGPIPE signal will
also be sent to the process.
SEE ALSO
getc(3S), getwc(3S), printf(3S), puts(3S), putwc(3S),