fwrite()

write to stream 

Function


SYNOPSIS

#include <stdio.h>

size_t fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);


DESCRIPTION

The fwrite() function writes, from the array pointed to by ptr, up to nitems members whose size is specified by size, to the stream pointed to by stream. A null byte does not necessarily terminate the sequence. The file-position indicator for the stream (if defined) is advanced by the number of bytes successfully written. If an error occurs, the resulting value of the file-position indicator for the stream is indeterminate.

The st_ctime and st_mtime fields of the file are marked for update between the successful execution of fwrite() and the next successful completion of a call to fflush() or fclose() on the same stream or a call to exit() or abort().


PARAMETERS

ptr 

Points to the buffer that is to hold the data written.

size 

Is the size of one of the elements to be written.

nitems 

Is the number of elements to be written.

stream 

Points to the output stream.


RETURN VALUES

The fwrite() function returns the number of members successfully written, which may be less than nitems if a write error is encountered. If size or nitems is zero, fwrite() returns 0 and does not affect the state of stream. On failure, it returns EOF and sets errno to one of the following values:

EACCES 

Another process has the file locked.

EAGAIN 

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

EBADF 

stream is not a valid stream opened for writing.

EFBIG 

The file is a regular file and an attempt was made to write at or beyond the offset maximum.

EINTR 

A signal interrupted the call.

EIO 

An output error occurred.

ENOMEM 

Memory could not be allocated for internal buffers.

ENOSPC 

An attempt is made to write to a full disk.

ENXIO 

A device error occurred.

EPIPE 

An attempt is made to write to a closed pipe or FIFO.


CONFORMANCE

ANSI/ISO 9899-1990.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

If the stream is from a file opened in text mode, linefeed is translated to carriage-return linefeed on output. No such translation occurs for files opened in binary mode.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
abort(), exit(), fclose(), fopen(), fread(), getc(), gets(), lseek(), printf(), putc(), puts(), read(), scanf(), write()


PTC MKS Toolkit 10.4 Documentation Build 39.