From: firewind Newsgroups: comp.os.msdos.djgpp Subject: Re: gets amd scanf Date: 3 Sep 1997 22:27:53 GMT Organization: Netcom Lines: 23 Message-ID: <5uko99$lk2@dfw-ixnews11.ix.netcom.com> References: <5ujllp$gu2$1 AT www DOT uno DOT edu> NNTP-Posting-Host: elp-tx2-03.ix.netcom.com Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 8bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk aflcs AT uno DOT edu wrote: > I am trying to read in a string with gets(); First, gets() is the antichrist. If you want to write decent programs, use fgets() which allows you to specify a maximum length, thus ensuring your buffer is not overrun. This is discussed in the comp.lang.c FAQ. > This works fine if it appears before any other input statements, > but if it appears after some scanf calls, then gets does not wait > for any input. IIRC, scanf() leaves the trailing newline in the input stream. The next time gets() is called, it will read in this newline and instantly return. The solution is to not intersparse different types of input functions. scanf() and gets() do not get along. IMHO, the best solution is to read in an entire line of text with fgets() and parse it with sscanf(). This is also discussed in the comp.lang.c FAQ. -- [- firewind -] [- email: firewind AT metroid DOT dyn DOT ml DOT org (home), firewind AT aurdev DOT com (work) -] [- "You're just jealous because the voices talk to -me-." -]