Compartilhar via


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

Routine Required Header Compatibility
putc <stdio.h> ANSI, Win 95, Win NT
putwc <stdio.h> or <wchar.h> ANSI, Win 95, Win NT
putchar <stdio.h> ANSI, Win 95, Win NT
putwchar <stdio.h> or <wchar.h> ANSI, Win 95, Win NT

For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version
LIBCMT.LIB Multithread static library, retail version
MSVCRT.LIB Import library for MSVCRT.DLL, retail version

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

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_puttc putc putc putwc
_puttchar putchar putchar putwchar

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

Stream I/O Routines

See Also   fputc, getc