🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.os2.programmer
Article #3275

fread()/fseek()/fwrite() problem?

#3275
From: Larry Salomon Jr.
Date: Tue, 05 Jan 1993 15:05
32 lines
1500 bytes
It is my code or is the following a problem?

pfFile=fopen("ABCD","r+b");
fread(achLine,sizeof(achLine),1,pfFile);
fread(&sMyStruct,sizeof(sMyStruct),1,pfFile);

/* @@ */
sMyStruct.bCheckedout=TRUE;
fseek(pfFile,sizeof(achLine),SEEK_SET);
fwrite(&sMyStruct,sizeof(sMyStruct),1,pfFile);
/* @@ */

(For those in comp.lang.c, I'm compiling under OS/2 2.0 with both the
 32-bit IBM C-Set/2 product and the 16-bit Microsoft C 6.0 product.)

With the C-Set/2, the next call to fread() fails, even though the file size
is 12000+ bytes and ftell() returns 44 just before the call.  With MSC 6.0
(obviously in 16-bit), the same thing happens.

If I move the code in between the '@@' to after the remainder of the file
processing and change the fseek(SEEK_SET) to a rewind(pfFile); fseek(SEEK_CUR)
everything works fine.

I've changed the code as above, but I'm curious why it didn't work the first
time.  If anyone has any ideas, please email me.  Thanks.

Cheers,
Q
-- 
"If you choose not to decide, you  | "My other body is in the shop" - seen
 still have made a choice" - Rush  |  on a T-shirt
------------------------------------------------------------------------
Technical Details
Message-ID: <C0Dz8s.4u4@panix.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!psinntp!panix!os2man

Show Full Headers
Complete Article Headers
Newsgroups: comp.os.os2.programmer,comp.lang.c
Path: arc1-ca.pugleaf.net!sparky!uunet!psinntp!panix!os2man
From: os2man@panix.com (Larry Salomon Jr.)
Subject: fread()/fseek()/fwrite() problem?
Message-ID: <C0Dz8s.4u4@panix.com>
Organization: PANIX Public Access Unix, NYC
Date: Tue, 5 Jan 1993 15:05:16 GMT
Lines: 32