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

Date: Thu, 30 Nov 1995 01:59:44 -0500 (EST)
From: Michael Phelps <morphine AT hops DOT cs DOT jhu DOT edu>
To: Iain N C Russell <russell>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: Re: Dodgy fgets in DJGPP? Help!

	I have had no trouble reading in ASCII files using the following routine:

	while (fgets(line, MAX_CHARS, fp) != NULL)
	{
		/* rest of routine here */
	}


						---Michael Phelps
						   morphine AT cs DOT jhu DOT edu


                               CH3
                               |
                               N
                             / |
                     ______/   |
                    /      \   CH2
             _____/         \__|__      
           //     \\        /  |  \\     
         //        \\______/___CH2 \\  
          \        /       \       /
           \______/         \_____/
          / ------ \       /      \
        OH           \   /         OH
                       O
 
                   Morphine

On 28 Nov 1995, Iain N C 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
> 

- Raw text -


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