#include <stdio.h> size_t fwrite(const void *ptr, size_t size, size_t count, FILE *f);
fwrite
writes one or more items of any type to the stream associated with
the FILE
object addressed by f
. The size of
each item is defined by size
, count
defines the number of items to be written, and
ptr
addresses the area containing the items to be written.
Although fwrite
may be used to write characters, it is more frequently
used to write noncharacter data, such as structured data. Except when
fwrite
is used to write printable character data, you should limit its
use to binary streams because the library's transformation of control
characters may change the data in unpredictable ways when reading and writing text streams.
Calls to fwrite
to write items of type typeval
commonly have the
form
typeval buf[count]; fwrite(buf, sizeof(typeval), count, f);
fwrite
returns the number of items successfully written. It returns 0
if no items are written because of an error.
fwrite
, remember that size
is not necessarily a
multiple of the record size, and that fwrite
ignores record boundaries.
fwrite
returns a value of 0, but count
is greater than 0, an
error occurred before any items were written.
count
is less than 1, no output takes place. If an error occurs
during the output operation, the file position is unpredictable.
fwrite
is illustrated in the example for fread
.
afwrite
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.