home *** CD-ROM | disk | FTP | other *** search
- 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
- From: jos@and.nl (Jos Horsmeier)
- Newsgroups: comp.lang.c
- Subject: Re: fwrite & fread
- Message-ID: <3890@dozo.and.nl>
- Date: 19 Nov 92 11:04:56 GMT
- References: <92324.000622U17868@uicvm.uic.edu>
- Organization: AND Software BV Rotterdam
- Lines: 36
-
- In article <92324.000622U17868@uicvm.uic.edu> U17868@uicvm.uic.edu writes:
- |I am using write & fread to read and write to a file. The structure that I
- |am writing has 194 bytes. After executing fwrite I check the value, in vari
- |able a which is 1 (correct), because I am writing one structure. Then I check
- |the values of returned by fclose and ferror and they are also correct i-e 0.
- |But when I quit from the program without writing more structures or without
- |running any other functions and look for the size of my file it shows that it
- |has 414 bytes. Actually, it should have 194 bytes. [ ... ]
-
- No it shouldn't. I assume you're working with 2 byte ints (sizeof(int) == 2),
- and no structure element padding. If I add up all the bytes, I get this:
-
- |typedef struct activity{
- | int id; /* total = 2 */
- | int mm; /* total = 4 */
- | int dd; /* total = 6 */
- | int yy; /* total = 8 */
- | char day[10]; /* total = 18 */
- | int hour; /* total = 20 */
- | int min; /* total = 22 */
- | int end_hour; /* total = 24 */
- | int end_min; /* total = 26 */
- | char location[25]; /* total = 51 */
- | char with_who[20]; /* total = 71 */
- | char phone[11]; /* total = 82 */
- | char subj[30]; /* total = 112 */
- | char note[300]; /* total = 412 */
- | int flag; /* total = 414 */
- |};
-
- BTW this is not a very useful type definition, you forgot to give
- the user defined type its own name.
-
- kind regards,
-
- Jos aka jos@and.nl
-