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;
HP-UX COMPATIBILITY
Level: HP-UX/RUN ONLY
Origin: System V
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 macros.
Fputc behaves like putc, but is a genuine function rather than a macro; it may therefore be used as an argument. 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 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)) will cause it to become buffered or line-buffered. When an output stream is unbuffered, information is queued for writing on the destination file or terminal as soon as written; when it is buffered, many characters are saved up and written as a block. When it is line-buffered, each line of output is queued for writing on the destination terminal as soon as the line is completed (that is, as soon as a new-line character is written or terminal input is requested). Fflush can also be used to explicitly write the buffer. Setbuf(3S) or setvbuf(3S) may be used to change the stream’s buffering strategy.
SEE ALSO
fclose(3S), ferror(3S), fopen(3S), fwrite(3S), getc(3S), fread(3S), printf(3S), puts(3S), setbuf(3S).
DIAGNOSTICS
On success, these functions each return the value they have written. On failure, they return the constant EOF. This will occur if the file stream is not open for writing or if the output file cannot be grown. Because EOF is a valid integer, ferror(3S) should be used to detect putw errors.
Line buffering may cause confusion or malfunctioning of programs which use standard I/O routines but use read(2) themselves to read from standard input. In cases where a large amount of computation is done after printing part of a line on an output terminal, it is necessary to fflush(3) the standard output before going off and computing so that the output will appear.
BUGS
Because it is implemented as a macro, putc treats incorrectly a stream argument with side effects. In particular, putc(c, ∗f++); doesn’t 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 (non-HP-UX) processor. For this reason putw should be used with care.
Hewlett-Packard — last mod. May 11, 2021