Mail Archives: djgpp/1995/11/30/16:21:55
Iain N C Russell (russell) wrote:
: Hi,
: 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?
: Thnaks for any help,
: Iain
First thing, you seem to have no mail address, so this has to be posted,
instead of mailed. It seem to me that you have not allocated enough
storage for line. This then causes fp to be overwritten (I suspect line is
an array). Try setting the array size to MAX_CHARS+1.
Hope this helps
Robert.
- Raw text -