home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / os2 / programm / 7327 < prev    next >
Encoding:
Internet Message Format  |  1993-01-05  |  1.5 KB

  1. Xref: sparky comp.os.os2.programmer:7327 comp.lang.c:19251
  2. Newsgroups: comp.os.os2.programmer,comp.lang.c
  3. Path: sparky!uunet!psinntp!panix!os2man
  4. From: os2man@panix.com (Larry Salomon Jr.)
  5. Subject: fread()/fseek()/fwrite() problem?
  6. Message-ID: <C0Dz8s.4u4@panix.com>
  7. Organization: PANIX Public Access Unix, NYC
  8. Date: Tue, 5 Jan 1993 15:05:16 GMT
  9. Lines: 32
  10.  
  11. It is my code or is the following a problem?
  12.  
  13. pfFile=fopen("ABCD","r+b");
  14. fread(achLine,sizeof(achLine),1,pfFile);
  15. fread(&sMyStruct,sizeof(sMyStruct),1,pfFile);
  16.  
  17. /* @@ */
  18. sMyStruct.bCheckedout=TRUE;
  19. fseek(pfFile,sizeof(achLine),SEEK_SET);
  20. fwrite(&sMyStruct,sizeof(sMyStruct),1,pfFile);
  21. /* @@ */
  22.  
  23. (For those in comp.lang.c, I'm compiling under OS/2 2.0 with both the
  24.  32-bit IBM C-Set/2 product and the 16-bit Microsoft C 6.0 product.)
  25.  
  26. With the C-Set/2, the next call to fread() fails, even though the file size
  27. is 12000+ bytes and ftell() returns 44 just before the call.  With MSC 6.0
  28. (obviously in 16-bit), the same thing happens.
  29.  
  30. If I move the code in between the '@@' to after the remainder of the file
  31. processing and change the fseek(SEEK_SET) to a rewind(pfFile); fseek(SEEK_CUR)
  32. everything works fine.
  33.  
  34. I've changed the code as above, but I'm curious why it didn't work the first
  35. time.  If anyone has any ideas, please email me.  Thanks.
  36.  
  37. Cheers,
  38. Q
  39. -- 
  40. "If you choose not to decide, you  | "My other body is in the shop" - seen
  41.  still have made a choice" - Rush  |  on a T-shirt
  42. ------------------------------------------------------------------------
  43.