fwrite

Writes elements to a stream

Local Servers:blocking
Remote Servers:blocking
Classification:ANSI
Platform:NLM
Service:Stream I/O

Syntax

  #include <stdio.h>  
   
  size_t fwrite  (  
     const void   *buf,   
     size_t        elsize,   
     size_t        nelem,   
     FILE         *fp);
  

Parameters

buf
(IN) Points to the buffer containing the data to write.
elsize
(IN) Specifies the size (in bytes) of each element.
nelem
(IN) Specifies the number of elements.
fp
(IN) Points to the file.

Return Values

This function also works on the DOS partition.

The fwrite function returns the number of complete elements that are successfully written. This value is less than the requested number of elements only if a write error occurs.

Remarks

The fwrite function writes nelem elements of elsize bytes each to the file specified by fp.

See Also

ferror, fopen

fwrite Example

The following example writes a simple student record containing binary data.

  #include <stdio.h>  
   
  struct student_data  
  {  
     int             student_id;  
     unsigned char   marks[10];  
  };  
   
  int write_data (FILE *fp, struct student_data *p)  
  {  
     return (fwrite ( p, sizeof (*p), 1, fp) );  
  }