Compartilhar via


fputc, fputwc, _fputchar, _fputwchar

Writes a character to a stream (fputc, fputwc) or to stdout (_fputchar, _fputwchar).

intfputc(intc**,FILE*stream);**

wint_tfputwc(wint_tc**,FILE*stream);**

int_fputchar(intc**);**

wint_t_fputwchar(wint_tc**);**

Function Required Header Compatibility
fputc <stdio.h> ANSI, Win 95, Win NT
fputwc <stdio.h> or <wchar.h> ANSI, Win 95, Win NT
_fputchar <stdio.h> Win 95, Win NT
_fputwchar <stdio.h> or <wchar.h> 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. For fputc and _fputchar, a return value of EOF indicates an error. For fputwc and _fputwchar, a return value of WEOF indicates an error.

Parameters

c

Character to be written

stream

Pointer to FILE structure

Remarks

Each of these functions writes the single character c to a file at the position indicated by the associated file position indicator (if defined) and advances the indicator as appropriate. In the case of fputc and fputwc, the file is associated with stream. If the file cannot support positioning requests or was opened in append mode, the character is appended to the end of the stream. Routine-specific remarks follow.

Routine Remarks
fputc Equivalent to putc, but implemented only as a function, rather than as a function and a macro.
fputwc Wide-character version of fputc. Writes c as a multibyte character or a wide character according to whether stream is opened in text mode or binary mode.
_fputchar Equivalent to fputc( stdout ). Also equivalent to putchar, but implemented only as a function, rather than as a function and a macro. Microsoft-specific; not ANSI-compatible.
_fputwchar Wide-character version of _fputchar. Writes c as a multibyte character or a wide character according to whether stream is opened in text mode or binary mode. Microsoft-specific; not ANSI-compatible.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined
_fputtc fputc fputc fputwc
_fputtchar _fputchar _fputchar _fputwchar

Example

/* FPUTC.C: This program uses fputc and _fputchar
 * to send a character array to stdout.
 */

#include <stdio.h>

void main( void )
{
   char strptr1[] = "This is a test of fputc!!\n";
   char strptr2[] = "This is a test of _fputchar!!\n";
   char *p;

   /* Print line to stream using fputc. */
   p = strptr1;
   while( (*p != '\0') && fputc( *(p++), stdout ) != EOF ) ;

   /* Print line to stream using _fputchar. */
   p = strptr2;
   while( (*p != '\0') && _fputchar( *(p++) ) != EOF )
      ;
}

Stream I/O Routines

See Also   fgetc, putc