Xref: news-dnh.mv.net comp.os.msdos.djgpp:3523 Newsgroups: comp.os.msdos.djgpp Path: news-dnh.mv.net!mv!news.sprintlink.net!newsfeed.internetmci.com!btnet!demon!sunsite.doc.ic.ac.uk!lut.ac.uk!R.Jaycocks1 From: R DOT Jaycocks1 AT lut DOT ac DOT uk (Robert Jaycocks) Subject: Re: Dodgy fgets in DJGPP? Help! Sender: usenet AT lut DOT ac DOT uk (Usenet-News) Date: Thu, 30 Nov 1995 16:16:46 GMT References: <49ere9$5io AT fs2 DOT abdn DOT ac DOT uk> Organization: Loughborough University, UK. Lines: 39 To: djgpp AT sun DOT soe DOT clarkson DOT edu Dj-Gateway: from newsgroup comp.os.msdos.djgpp 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.