/* File: fwrite2.c
   Practicing with fwrite() 
*/

#include <stdio.h>

typedef struct {
   int hour ;
   short minute ;
   float sec ;
} time_type ;

main() {
time_type when ;
int r ;
FILE *ofile ;

   printf("sizeof(int) = %d\n", sizeof(int)) ;
   printf("sizeof(short) = %d\n", sizeof(short)) ;
   printf("sizeof(float) = %d\n", sizeof(float)) ;

   when.hour = 1 ;
   when.minute = 56 ;
   when.sec = 51.3125 ;

   ofile = fopen("binary", "wb") ;
   r = fwrite(&when, sizeof(time_type), 1, ofile) ;

   printf("%d item(s) were written to the output file\n", r) ;

   fclose(ofile) ;
}
