C Programming/stdio.h/fwrite

The  and   functions respectively provide the file operations of input and output. and  are declared in. It usually wraps write.

Writing a file using fwrite
fwrite is defined as

function writes a block of data to the stream. It will write an array of  elements to the current position in the stream. For each element, it will write  bytes. The position indicator of the stream will be advanced by the number of bytes written successfully.

The function will return the number of elements written successfully. The return value will be equal to  if the write completes successfully. In case of a write error, the return value will be less than.

Example
The following program opens a file named sample.txt, writes an array of characters to the file, and closes it.