putc, putchar

Description

Writes a character to a stream (putc) or to stdout (putchar).

#include <stdio.h>

int putc( int c, FILE *stream );

int putchar( int c );

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. The putchar routine is identical to putc(c, stdout).

These routines are implemented as both macros and functions. See “Choosing Between Functions and Macros” for a discussion of how to select between the macro and function forms.

Return Value

The putc and putchar routines return the character written, or EOF in the case of an error. Any integer can be passed to putc, but only the lower 8 bits are written.

Compatibility

putc

Standards:ANSI, UNIX

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:DOS32X

putchar

Standards:ANSI, UNIX

16-Bit:DOS, QWIN

32-Bit:DOS32X

See Also

fputc, _fputchar, getc, getchar

Example

/* PUTC.C: This program uses putc to write buffer to a stream.

* If an error occurs, the program will stop 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;

/* 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