United States-English |
|
|
HP-UX Reference > Pputc(3S)HP-UX 11i Version 3: February 2007 |
|
NAMEputc(), putchar(), fputc(), putw() — put character or word on a stream DESCRIPTION
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. APPLICATION USAGEAfter putc(), fputc(), putchar(), or putw() is applied to a stream, the stream becomes byte-oriented (see orientation(5)). RETURN VALUEOn 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. ERRORSputc(), 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 causing an underlying write() call to be invoked, and:
Additional errno values can be set by the underlying write() function (see write(2)). WARNINGSThe putc() and putchar() routines are implemented as both library functions and macros. The macro versions, which are used by default, are defined in <stdio.h>. To obtain the library function either use a #undef to remove the macro definition or, if compiling in ANSI-C mode, enclose the function name in parentheses or use the function address. The following example illustrates each of these methods: #include <stdio.h> #undef putc ... main() { int (*put_char()) (); ... return_val=putc(c,fd); ... return_val=(putc)(c,fd1); ... put_char = putchar; }; Line buffering may cause confusion or malfunctioning of programs that use standard I/O routines but use read() themselves to read from standard input. When a large amount of computation is done after printing part of a line on an output terminal, it is necessary to fflush() (see fclose(3S)) the standard output before beginning the computation. The macro version of putc() incorrectly treats the argument stream with side effects. In particular, the following call may not work as expected: putc(c, *f++); The function version of putc() or 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 readable by getw() on a different processor. putw_unlocked() is an obsolescent interface supported only for compatibility with existing DCE applications. New multithreaded applications should use putc(), putchar() and putw(). |
Printable version | ||
|