C examples for stdio.h:fwrite
function
<cstdio> <stdio.h>
Write block of data to stream
size_t fwrite ( const void * ptr, size_t size, size_t count, FILE * stream );
Parameter | Description |
---|---|
ptr | Pointer to the array of elements to be written. |
size | Size in bytes of each element to be written. |
count | Number of elements, each one with a size of size bytes. |
stream | FILE object. |
On success, total number of elements written is returned.
#include <stdio.h> int main ()/*w w w . j av a2 s . c o m*/ { FILE * pFile; char buffer[] = { 'x' , 'y' , 'z' }; pFile = fopen ("main.cpp", "wb"); fwrite (buffer , sizeof(char), sizeof(buffer), pFile); fclose (pFile); return 0; }