home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_08_11 / 8n11105a < prev    next >
Text File  |  1990-08-09  |  906b  |  39 lines

  1.  
  2. ******
  3. Listing 4
  4.  
  5.  
  6.    #include <stdio.h>
  7.  
  8.    struct s_date
  9.        {
  10.        int day;
  11.        int month;
  12.        char filler;  /* Just to get some packing bytes (perhaps) */
  13.        int year;
  14.        };
  15.  
  16.    main()
  17.        {
  18.        FILE *file;
  19.        static struct s_date date = {1,2,' ',3};
  20.        static struct s_date date2 = {4,5,' ',6};
  21.  
  22.        printf("\n Size of the structure is %d", 
  23.            sizeof(struct s_date));
  24.  
  25.        /* Write two structures out */
  26.        file = fopen("DATA.DAT", "w");
  27.        fwrite(&date, sizeof(struct s_date), 1, file);
  28.        fwrite(&date2, sizeof(struct s_date), 1, file);
  29.        fclose(file);
  30.        
  31.        file = fopen("DATA.DAT","r");
  32.        /* Note reversal of which date is read */
  33.        fread(&date2, sizeof(struct s_date), 1, file);
  34.        fread(&date, sizeof(struct s_date), 1, file);
  35.        fclose(file);
  36.        }
  37. *********
  38.  
  39.