putc, putchar, fputc, putw - put character or word on a stream


#include <stdio_p.h>

int putc (c, stream)
char c;
FILE *stream;

putchar (c)

fputc (c, stream)
char c;
FILE *stream;

putw (w, stream)
int w;
FILE *stream;


putc appends the character c to the named output stream. It returns the character written.

putchar(c) is defined as putc(c, stdout).

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 takes less space per invocation.

putw appends word (i.e., int ) w to the output stream. putw neither assumes nor causes special alignment in the file.

The standard stream stdout is normally buffered if and only if the output does not refer to a terminal; this default may be changed by setbuf(3P). The standard stream stderr is by default unbuffered unconditionally, but use of freopen see ( fopen(3P) will cause it to become unbuffered; setbuf, again, will set the state to whatever is desirerd. When an output stream is unbuffered information appears on the destination file or a terminal as soon as written; when it is buffered many characters are saved up and written as a block. See also fflush in fclose(3P).


ferror(3P) , fopen(3P) , fwrite(3P) , getc(3P) , printf(3P) , puts(3P).


These functions return the constant EOF upon error. Since this is a good integer, ferror(3P) should be used to detect putw errors.


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.