Exportar (0) Imprimir
Expandir todo
div
eof
Expandir Minimizar

putchar, putwchar

Write a character to stdout.


int putchar(
   int c 
);
wint_t putwchar(
   wchar_t c 
);

Parameters

c

Character to be written.

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. If passed a null pointer for stream, these functions generate an invalid parameter exception, as described in Parameter Validation. If execution is allowed to continue, they return EOF or WEOF and set errno to EINVAL.

See _doserrno, errno, _sys_errlist, and _sys_nerr for more information on these, and other, error codes.

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.

The versions with the _nolock suffix are identical except that they are not protected from interference by other threads. They may be faster since they do not incur the overhead of locking out other threads. Use these functions only in thread-safe contexts such as single-threaded applications or where the calling scope already handles thread isolation.

Generic-Text Routine Mappings
TCHAR.H routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined

_puttchar

putchar

putchar

putwchar

Routine Required header Compatibility

putchar

<stdio.h>

ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

putwchar

<stdio.h> or <wchar.h>

ANSI, Windows 95, Windows 98, Windows 98 Second Edition, Windows Millennium Edition, Windows Millennium Edition, Windows NT 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003

For additional compatibility information, see Compatibility in the Introduction.

All versions of the C run-time libraries.

// crt_putchar.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;

   for( p = buffer; (ch != EOF) && (*p != '\0'); p++ )
      ch = putchar( *p );
}

This is the line of output

Adiciones de comunidad

AGREGAR
Mostrar:
© 2014 Microsoft