Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
putc, putwc, putchar, putwchar
Writes a character to a stream (putc, putwc) or to stdout (putchar, putwchar).
intputc(intc**,FILE*stream);**
wint_tputwc(wint_tc**,FILE*stream);**
intputchar(intc**);**
wint_tputwchar(wint_tc**);**
For additional compatibility information, see Compatibility in the Introduction.
Libraries
Return Value
Each of these functions returns the character written. To indicate an error or end-of-file condition, putc and putchar return EOF; putwc and putwchar return WEOF. For all four routines, use ferror or feof to check for an error or end of file.
Parameters
c
Character to be written
stream
Pointer to FILE structure
Remarks
The putc routine writes the single character c to the output stream at the current position. Any integer can be passed to putc, but only the lower 8 bits are written. The putchar routine is identical to putc(c,stdout ). For each routine, if a read error occurs, the error indicator for the stream is set. putc and putchar are similar to fputc and _fputchar, respectively, but are implemented both as functions and as macros (see Choosing Between Functions and Macros). putwc and putwchar are wide-character versions of putc and putchar, respectively.
Generic-Text Routine Mappings
Example
/* PUTC.C: This program uses putc to write buffer
* to a stream. If an error occurs, the program
* stops before writing the entire buffer.
*/
#include <stdio.h>
void main( void )
{
FILE *stream;
char *p, buffer[] = "This is the line of output\n";
int ch;
ch = 0;
/* Make standard out the stream and write to it. */
stream = stdout;
for( p = buffer; (ch != EOF) && (*p != '0円'); p++ )
ch = putc( *p, stream );
}
Output
This is the line of output