PUTC(3S) UNIX Programmer's Manual PUTC(3S) NAME putc, putchar, fputc, putw - put character or word on a stream SYNOPSIS #include int putc (c, stream) char c; FILE *stream; putchar (c) fputc (c, stream) FILE *stream; putw (w, stream) int w; FILE *stream; HP-UX COMPATIBILITY Level: HP-UX/RUN ONLY Origin: System V DESCRIPTION _P_u_t_c appends the character _c to the named output _s_t_r_e_a_m. It returns the character written. _P_u_t_c_h_a_r(_c) is defined as _p_u_t_c(_c, _s_t_d_o_u_t). _F_p_u_t_c behaves like _p_u_t_c, but is a genuine function rather than a macro; it may therefore be used as an argument. _F_p_u_t_c runs more slowly than _p_u_t_c, but takes less space per invocation. _P_u_t_w appends the word (i.e., int) _w to the output _s_t_r_e_a_m. _P_u_t_w neither assumes nor causes special alignment in the file. The standard stream _s_t_d_o_u_t is normally buffered. However, if the output refers to a terminal then the stream is line- buffered. When a stream is line buffered, its buffer will be flushed when a read(2) from the standard input is neces- sary, when a "\n" is written to stdout, when the buffer is full, or when fflush(stdout) is called. This default may be changed by _s_e_t_b_u_f(3S). The standard stream _s_t_d_e_r_r is by default unbuffered uncondi- tionally, but use of _f_r_e_o_p_e_n (see _f_o_p_e_n(3S)) will cause it to become unbuffered; _s_e_t_b_u_f, again, will set the state to whatever is desired. When an output stream is unbuffered information appears on the destination file or terminal as soon as written; when it is buffered many characters are saved up and written as a block. See also _f_f_l_u_s_h (under _f_c_l_o_s_e(3S)). SEE ALSO ferror(3S), fopen(3S), fread(3S), getc(3S), printf(3S), puts(3S). DIAGNOSTICS These functions return the constant EOF upon error. Since this is a good integer, _f_e_r_r_o_r(3S) should be used to detect _p_u_t_w errors. Line buffering may cause confusion or malfunctioning of pro- grams which use standard I/O routines but use _r_e_a_d(2) them- selves 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 use _f_f_l_u_s_h (see _f_c_l_o_s_e(3S)) to flush the standard output before going off and computing so that the output will appear. BUGS Because it is implemented as a macro, _p_u_t_c treats incorrectly a _s_t_r_e_a_m argument with side effects. In partic- ular, putc(c, *f++); doesn't work sensibly.