fputc, fputwc

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see fputc, fputwc on docs.microsoft.com. Writes a character to a stream.

int fputc(  
   int c,  
   FILE *stream   
);  
wint_t fputwc(  
   wchar_t c,  
   FILE *stream   
);  

Parameters

c
Character to be written.

stream
Pointer to FILE structure.

Each of these functions returns the character written. For fputc, a return value of EOF indicates an error. For fputwc, a return value of WEOF indicates an error. If stream is NULL, these functions invoke the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, they return EOF and set errno to EINVAL.

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

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.

The two functions behave identically if the stream is opened in ANSI mode. fputc does not currently support output into a UNICODE stream.

The versions with the _nolock suffix are identical except that they are not protected from interference by other threads. For more information, see_fputc_nolock, _fputwc_nolock.

Routine-specific remarks follow.

RoutineRemarks
fputcEquivalent to putc, but implemented only as a function, rather than as a function and a macro.
fputwcWide-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.

Generic-Text Routine Mappings

TCHAR.H routine_UNICODE & _MBCS not defined_MBCS defined_UNICODE defined
_fputtcfputcfputcfputwc
FunctionRequired header
fputc<stdio.h>
fputwc<stdio.h> or <wchar.h>

The console is not supported in Windows 8.x Store apps. The standard stream handles that are associated with the console—stdin, stdout, and stderr—must be redirected before C run-time functions can use them in Windows 8.x Store apps. For additional compatibility information, see Compatibility.

// crt_fputc.c  
// This program uses fputc  
// to send a character array to stdout.  
  
#include <stdio.h>  
  
int main( void )  
{  
   char strptr1[] = "This is a test of fputc!!\n";  
   char *p;  
  
   // Print line to stream using fputc.   
   p = strptr1;  
   while( (*p != '\0') && fputc( *(p++), stdout ) != EOF ) ;  
  
}  

This is a test of fputc!!  

Stream I/O
fgetc, fgetwc
putc, putwc

Show: