title | ms.custom | ms.date | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | apiname | apilocation | apitype | f1_keywords | dev_langs | helpviewer_keywords | ms.assetid | caps.latest.revision | author | ms.author | manager | translation.priority.ht | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fwrite | Microsoft Docs |
11/04/2016 |
|
article |
|
|
DLLExport |
|
|
|
7afacf3a-72d7-4a50-ba2e-bea1ab9f4124 |
18 |
corob-msft |
corob |
ghogen |
|
Writes data to a stream.
size_t fwrite(
const void *buffer,
size_t size,
size_t count,
FILE *stream
);
buffer
Pointer to data to be written.
size
Item size, in bytes.
count
Maximum number of items to be written.
stream
Pointer to FILE
structure.
fwrite
returns the number of full items actually written, which may be less than count
if an error occurs. Also, if an error occurs, the file-position indicator cannot be determined. If either stream
or buffer
is a null pointer, or if an odd number of bytes to be written is specified in Unicode mode, the function invokes the invalid parameter handler, as described in Parameter Validation. If execution is allowed to continue, this function sets errno
to EINVAL
and returns 0.
The fwrite
function writes up to count
items, of size
length each, from buffer
to the output stream
. The file pointer associated with stream
(if there is one) is incremented by the number of bytes actually written. If stream
is opened in text mode, each linefeed is replaced with a carriage-return – linefeed pair. The replacement has no effect on the return value.
When stream
is opened in Unicode translation mode—for example, if stream
is opened by calling fopen
and using a mode parameter that includes ccs=UNICODE
, ccs=UTF-16LE
, or ccs=UTF-8
, or if the mode is changed to a Unicode translation mode by using _setmode
and a mode parameter that includes _O_WTEXT
, _O_U16TEXT
, or _O_U8TEXT
—buffer
is interpreted as a pointer to an array of wchar_t
that contains UTF-16 data. An attempt to write an odd number of bytes in this mode causes a parameter validation error.
Because this function locks the calling thread, it is thread-safe. For a non-locking version, see _fwrite_nolock
.
Function | Required header |
---|---|
fwrite |
<stdio.h> |
For additional compatibility information, see Compatibility.
See the example for fread.