This documentation is archived and is not being maintained.

putc, putwc, putchar, putwchar

Write a character to a stream (putc, putwc) or to stdout (putchar, putwchar).

int putc(
   int c,
   FILE *stream 
wint_t putwc(
   wchar_t c,
   FILE *stream 
int putchar(
   int c 
wint_t putwchar(
   wchar_t c 


Character to be written.
Pointer to FILE structure.

Return Value

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.


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

TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_puttc putc putc putwc
_puttchar putchar putchar putwchar


Routine Required header Compatibility
putc <stdio.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
putwc <stdio.h> or <wchar.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
putchar <stdio.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
putwchar <stdio.h> or <wchar.h> ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.


All versions of the C run-time libraries.


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

int 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 );


This is the line of output

See Also

Stream I/O Routines | fputc | getc | Run-Time Routines and .NET Framework Equivalents