fputc, fputwc, _fputchar, _fputwchar
Writes a character to a stream (fputc, fputwc) or to stdout (_fputchar, _fputwchar).
int fputc( int c, FILE *stream ); wint_t fputwc( wchar_t c, FILE *stream ); int _fputchar( int c ); wint_t _fputwchar( wchar_t c );
Parameters
- c
- Character to be written.
- stream
- Pointer to FILE structure.
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.
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 |
Requirements
| Function | Required header | Compatibility |
|---|---|---|
| fputc | <stdio.h> | ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP |
| fputwc | <stdio.h> or <wchar.h> | ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP |
| _fputchar | <stdio.h> | Win 98, Win Me, Win NT, Win 2000, Win XP |
| _fputwchar | <stdio.h> or <wchar.h> | Win 98, Win Me, Win NT, Win 2000, Win XP |
For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
// crt_fputc.c
/* This program uses fputc and _fputchar
* to send a character array to stdout.
*/
#include <stdio.h>
int 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 )
;
}
Output
This is a test of fputc!! This is a test of _fputchar!!
See Also
Stream I/O Routines | fgetc | putc | Run-Time Routines and .NET Framework Equivalents