putc.3s (2010 09)

p
putc(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);
int putc_unlocked(int c, FILE *stream);
int putchar_unlocked(int c);
Obsolescent Interfaces
int putw_unlocked(int w, FILE *stream);
DESCRIPTION
putc() Writes the character c onto the output stream at the position where the file pointer, if
defined, is pointing.
putchar(c) is defined as putc(c, stdout)
. putc() and
putchar() are defined both as macros and as functions.
fputc() Same as putc(), but is a function rather than a macro, and can therefore be used as an
argument. fputc() runs more slowly than putc(), but takes less space per invoca-
tion, and its name can be passed as an argument to a function.
putw() Writes the word (i.e., int 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.
putw() neither assumes nor causes special alignment in the
file.
Output streams, with the exception of the standard error stream
stderr, 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, stderr, is by default unbuffered, but use of freopen() (see fopen (3S)) causes it to become
buffered or line-buffered. setbuf() or setvbuf() (see setbuf (3S)) can be used to change the stream’s
buffering strategy. putc_unlocked()
, putchar_unlocked(), put character on a stream.
Obsolescent Interfaces
putw_unlocked() put character or word on a stream.
APPLICATION USAGE
After
putc(), fputc(), putchar(),orputw() is applied to a stream, the stream becomes byte-
oriented (see orientation (5)).
RETURN VALUE
On success,
putc(), putc_unlocked(), fputc(), putchar() and putchar_unlocked()
each
return the value they have written. On failure, they return the constant
EOF, set the error indicator for
the stream, and set errno to indicate the error.
On success,
putw() and putw_unlocked() return 0. Otherwise, a non-zero value is returned, the
error indicator for the stream is set, and errno is set to indicate the error.
ERRORS
putc(), putc_unlocked(), putchar(), putchar_unlocked()
, fputc(), putw(), and
putw_unlocked() fail if, either the stream is unbuffered or stream ’s buffer needed to be flushed caus-
ing an underlying write() call to be invoked, and:
[EAGAIN] The O_NONBLOCK flag is set for the file descriptor underlying stream and the pro-
cess 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
maximum file size (see ulimit (2)).
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (2 pages)