delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/11/30/06:50:20

Date: Thu, 30 Nov 1995 11:50:22 +0300
From: "Alexander V. Lukyanov" <lav AT video DOT yars DOT free DOT net>
To: djgpp AT sun DOT soe DOT clarkson DOT edu, russell
Subject: Re: Dodgy fgets in DJGPP? Help!

> From: Iain N C Russell <russell AT delorie DOT com>
> Date: 28 Nov 1995 11:22:49 GMT
>
> I've started using DJGPP V2 to compile the database-type program
> I'm writing and have come across a strange problem that does not
> occur when I compile with BC3.1...
>
> I have 3 similar routines for reading different types of files, all
> using a basic
>   while(!feof(fp)) {
>     fgets(line, MAX_CHARS, fp);
>     /* other code here, none of it altering fp */
>   }
>
> loop.
>
> The thing is, one routine works fine.
>
> The second reads the first line, but then fp becomes 0 for some
> unknown reason. According to ferror(fp) there is no problem with fp, though
> this may be because it has become 0 by the time it is checked....The
> consequence is that is gets into an infinite loop, trying to read a line from a
> NULL stream.
>
> The third routine reads lines until the last one then does the same as above.
>
> Since the routines work fine under Borland, is there some known problem with
> fgets in DJGPP or does it just behave slightly differently for some reason?

I don't think the problem is in fgets. fgets() just cannot modify fp
since it is passed by value. If fp is automatic and there is automatic
arrays, try checking array bounds. In any case, there should be invalid
memory reference, because a variable cannot be modified 'for some unknown
reason' otherwise...
---
Alexander Lukyanov
lav AT video DOT yars DOT free DOT net

- Raw text -


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