From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: problem with gets Date: Wed, 12 Nov 1997 09:33:40 +0000 Organization: Two pounds of chaos and a pinch of salt Lines: 32 Message-ID: <346977F4.3EAD@cs.com> References: <01bcecfb$03800800$964c58d1 AT p133> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp218.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hein wrote: > > Problem is: > in my main function I'm calling on other functions which uses gets to get > user input. > it compiles fine but when it is run it skips some of the gets comands, > although they all use exactly the same commands. Ive used fflush to clear > the keyboard buffer. fflush() does NOT clear the input buffer. That it does so under Borland, et. al. is an example of these compilers' noncompliance with the ANSI standard. There are a number of ways to handle this sort of problem: 1) Use gets(), or the safer fgets(), for all input, and read the results from the string instead of directly from stdin. Replace all calls to scanf() with gets()/sscanf(); replace all calls to getchar() with gets(), etc. 2) Clear the input buffer in an ANSI-safe way, such as "while ( getchar() != '\n' ) ;", after each function that leaves characters in the buffer. 3) Read your input from the console using conio functions. hth -- --------------------------------------------------------------------- | John M. Aldrich | "History does not record anywhere at | | aka Fighteer I | any time a religion that has any | | mailto:fighteer AT cs DOT com | rational basis." | | http://www.cs.com/fighteer | - Lazarus Long | ---------------------------------------------------------------------