Skip to content

Latest commit

 

History

History
82 lines (61 loc) · 3.19 KB

File metadata and controls

82 lines (61 loc) · 3.19 KB
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 ms.workload
fwrite | Microsoft Docs
11/04/2016
cpp-standard-libraries
reference
fwrite
msvcrt.dll
msvcr80.dll
msvcr90.dll
msvcr100.dll
msvcr100_clr0400.dll
msvcr110.dll
msvcr110_clr0400.dll
msvcr120.dll
msvcr120_clr0400.dll
ucrtbase.dll
api-ms-win-crt-stdio-l1-1-0.dll
DLLExport
fwrite
C++
streams, writing data to
fwrite function
7afacf3a-72d7-4a50-ba2e-bea1ab9f4124
18
corob-msft
corob
ghogen
cplusplus

fwrite

Writes data to a stream.

Syntax

size_t fwrite(
   const void *buffer,
   size_t size,
   size_t count,
   FILE *stream
);

Parameters

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.

Return Value

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.

Remarks

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_U8TEXTbuffer 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.

Requirements

Function Required header
fwrite <stdio.h>

For additional compatibility information, see Compatibility.

Example

See the example for fread.

See Also

Stream I/O
_setmode
fread
_fwrite_nolock
_write