fwrite function
| Prototype |
size_t fwrite (void * Buffer, size_t Size, size_t Count, FILE * Stream); |
| Purpose | To write data to a file stream. |
| Header File | #include <stdio.h> |
| Parameters |
| Buffer | Pointer to an area of variables where the data is to be placed |
| Size | Size of each variable item |
| Count | Number of variable items |
| Stream | Pointer to an open FILE |
|---|
|
|---|
| Return Value |
Count of items actually writen.
|
| Notes |
- The number of bytes writen will be Size times the return value.
- If an error occurs before Count items are writen, the return
value (count of items actually writen) will be less than the number requested.
- If a file is opened for update, both reads and writes are allowed; however,
they must be separated from each other by an intervening seek or rewind.
- The type size_t is defined in stdio.h.
|
| Example |
#include
. . .
FILE * Temperatures;
int Temperature [24];
size_t Count;
size_t Request;
. . .
Count = fwrite (Temperature, sizeof (int), Request, Temperatures);
if (Count == Request)
printf ("All items were written successfully");
else
printf ("An error occurred during write.");
|
| Related functions |
|