fwrite function

Prototype size_t fwrite (void * Buffer, size_t Size, size_t Count, FILE * Stream);
PurposeTo write data to a file stream.
Header File#include <stdio.h>
Parameters
BufferPointer to an area of variables where the data is to be placed
SizeSize of each variable item
CountNumber of variable items
StreamPointer 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 <stdio.h> . . . 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
fopen fclose fread fwrite fseek rewind ftell

c/c++ Index