Borland C++ reference

fwrite

raw OCR

Writes to a stream.

Defined in header <stdio.h>

Syntax

#include <stdio.h>
size_t fwrite(const  void  *ptr, size_t size, size_t n, FILE *stream);

Portability

DOSUNIXWindowsANSI CC++ only
■■■■

Remarks

fwrite appends n items of data, each of length size bytes, to the given output file. The data written begins at ptr.

The total number of bytes written is (n x size).

ptr in the declarations is a pointer to any object.

Return value

On successful completion, fwrite returns the number of items (not bytes) actually written. It returns a short count on error.

See also

Example

#include <stdio.h>

struct mystruct
{
  int i;
  char ch;
};
int main(void)
{
   FILE *stream;
   struct mystruct s;
   /* open file TEST.$$$ */
   if ((stream = fopen("TEST.$$$",  "wb")) == NULL) {
      fprintf(stderr, "Cannot open output  file.\n");
      return 1;
   }
   s.i = 0;
   s.ch = 'A' ;
   fwrite(&s, sizeof(s), 1, stream);  /* write struct s to file */
   fclose(stream);                   /* close  file */
return

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.