delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2013/12/03/11:30:32

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Rod Pemberton" <dont_use_email AT xnohavenotit DOT cnm>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Question about different behavior of fclose/fread on plain dos
and windows.
Date: Tue, 03 Dec 2013 11:16:25 -0500
Organization: Aioe.org NNTP Server
Lines: 54
Message-ID: <op.w7ix5n0b5zc71u@localhost>
References: <529D448A DOT 7050208 AT gmx DOT de> <op DOT w7ive7du5zc71u AT localhost>
NNTP-Posting-Host: CNsg4fVcCsvs3UaOgZtQCw.user.speranza.aioe.org
Mime-Version: 1.0
X-Complaints-To: abuse AT aioe DOT org
User-Agent: Opera Mail/12.16 (Linux)
X-Notice: Filtered by postfilter v. 0.8.2
Bytes: 2611
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Tue, 03 Dec 2013 10:17:21 -0500, Rod Pemberton  
<dont_use_email AT xnohavenotit DOT cnm> wrote:
> On Mon, 02 Dec 2013 21:40:10 -0500, Juan Manuel Guerrero  
> <juan DOT guerrero AT gmx DOT de> wrote:

>> Please inspect the code snippet below:
>>
>> [...]
>
> That seems to work correctly for MS-DOS v7.10 and Windows SE
> DOS console window.  Sorry, I just realized I didn't check
> v2.04 for that.  I'd have to reboot and loose this reply to
> you to check. Let me know if you want me to test that.
>

Okay, that code I posted works for v2.04 too.

> I tried it both with and without "file.txt".  Some solutions
> I attempted didn't update "file.txt" with a new "pipapo", but
> were reading the old "pipapo" in "file.txt", i.e., the previously
> saved text.  So, I also edited "file.txt" changed "pipapo" to
> "zzzzzz" to verify "pipapo" was actually being updated when the
> program executed.  Of course, the version above just deletes
> "file.txt" each time.
>
> One of the solutions I looked at which appeared promising at
> first was changed fr's "r" mode to "a+", but it had the
> "zzzzzz" problem.  I'm guessing there is a possibility that an
> "a+" mode for fr and the freopen() might be all that's needed.
> So, that might be worth trying too.  It'd be easier solution
> if it works.
>

Well, that was a good hunch, it seems...

It works here for MS-DOS v7.10, Windows SE, and DJGPP
v2.03 and v2.04.  It don't have MS-DOS 6.22.

So, all you should need to do is:

1) change fr's open declaration from "r" to "a+":

    FILE *fr = fopen("file.txt", "a+");

2) insert a freopen() with "r" mode after fseek():

   fseek(fr, 0, SEEK_SET);
   /* reopen read file */
   freopen("file.txt", "r", fr);

Hope that helps.


Rod Pemberton

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019