home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16785 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  1.8 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!math.fu-berlin.de!unidui!rrz.uni-koeln.de!Germany.EU.net!mcsun!sun4nl!and!jos
  2. From: jos@and.nl (Jos Horsmeier)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: fwrite & fread
  5. Message-ID: <3890@dozo.and.nl>
  6. Date: 19 Nov 92 11:04:56 GMT
  7. References: <92324.000622U17868@uicvm.uic.edu>
  8. Organization: AND Software BV Rotterdam
  9. Lines: 36
  10.  
  11. In article <92324.000622U17868@uicvm.uic.edu> U17868@uicvm.uic.edu writes:
  12. |I am using write & fread to read and write to a file. The structure that I
  13. |am writing has 194 bytes. After executing fwrite I check the value, in vari
  14. |able a which is 1 (correct), because I am writing one structure. Then I check
  15. |the values of returned by fclose and ferror and they are also correct i-e 0.
  16. |But when I quit from the program without writing more structures or without
  17. |running any other functions and look for the size of my file it shows that it
  18. |has 414 bytes. Actually, it should have 194 bytes. [ ... ]
  19.  
  20. No it shouldn't. I assume you're working with 2 byte ints (sizeof(int) == 2),
  21. and no structure element padding. If I add up all the bytes, I get this:
  22.  
  23. |typedef struct activity{
  24. |    int  id;        /* total =   2 */
  25. |    int  mm;        /* total =   4 */
  26. |    int  dd;        /* total =   6 */
  27. |    int  yy;        /* total =   8 */
  28. |    char day[10];        /* total =  18 */
  29. |    int  hour;        /* total =  20 */
  30. |    int  min;        /* total =  22 */
  31. |    int  end_hour;        /* total =  24 */
  32. |    int  end_min;        /* total =  26 */
  33. |    char location[25];    /* total =  51 */
  34. |       char with_who[20];    /* total =  71 */
  35. |    char phone[11];        /* total =  82 */
  36. |    char subj[30];        /* total = 112 */
  37. |    char note[300];        /* total = 412 */
  38. |       int  flag;        /* total = 414 */
  39. |};
  40.  
  41. BTW this is not a very useful type definition, you forgot to give
  42. the user defined type its own name. 
  43.  
  44. kind regards,
  45.  
  46. Jos aka jos@and.nl
  47.