Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

fputc - put byte on stream

&pagelevel(4)&pagelevel


Descripti

Syntax

#include <stdio.h>

int fputc(int c, FILE *stream); 

Description

fputc() converts the byte specified by c to an unsigned char and writes it to the output stream pointed to by stream at the position indicated by the associated file position indicator for the stream, if defined. The file position indicator is then advanced appropriately. If the file cannot support positioning requests, or if the stream was opened with append mode, the byte is appended to the output stream.

The structure components st_ctime and st_mtime of the file are marked for changing between successful execution of fputc() and the next successful completion of a call to fflush() or fclose() for the same data stream or a call to exit() or abort() (see sys/stat.h).

Return val.

The written value


if successful.

EOF

if an error occurs, e.g. because stream was not opened for writing or the output file could not be extended. The error indicator for the stream is set and errno is set to indicate the error.

Errors

fputc() will fail if: 

 

EAGAIN

The O_NONBLOCK flag is set for the file descriptor underlying stream and the process would be delayed in the write operation.

 

EBADF

The file descriptor underlying stream is not a valid file descriptor open for writing.

 

EFBIG

An attempt was made to write to a file that exceeds the maximum file size or the process file size limit (see ulimit()).

 

EINTR

The write operation was terminated due to the receipt of a signal, and no data was transferred.

 

EIO

The process is a member of a background process group attempting to write to its controlling terminal, TOSTOP is set, the process is neither ignoring nor blocking SIGTTOU and the process group of the process is orphaned.

 

ENOSPC

There was no free space remaining on the device containing the file.


EPIPE

An attempt was made to write to a pipe or FIFO that is not open for reading by any process. A SIGPIPE signal will also be sent to the process.

If threads are used, then the function affects the process or a thread in the following manner: If an EPIPE error occurs, the SIGPIPE signal is not sent to the process, but is sent to the calling thread instead.

Notes

The characters are not written immediately to the external file, but are stored in an internal C buffer (see section “Buffering streams”).

On output to text files, control characters for white space (\n, \t, etc.) are converted to their appropriate effect in accordance with the type of text file (see section “White-spacecharacters”).

fputc() does not execute as fast as putc(), but requires less memory per call.

The program environment determines whether fputc() is executed for a BS2000 or POSIX file.

See also

ferror(), fopen(), putc(), puts(), setbuf(), stdio.h, sys/stat.h.