Mail Archives: djgpp/2013/12/03/11:30:32
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 -