From: hhkraemer AT web DOT de (Horst Kraemer) Newsgroups: comp.os.msdos.djgpp Subject: Re: fflush (in djgpp) Date: Tue, 17 Apr 2001 18:33:48 GMT Lines: 39 Message-ID: <3adc82a7.241519997@news.cis.dfn.de> References: <9aqfuu$fnb$1 AT uranium DOT btinternet DOT com> <3ADC5A6A DOT C9F50B46 AT falconsoft DOT be> NNTP-Posting-Host: b3e9a.pppool.de (213.7.62.154) X-Trace: fu-berlin.de 987532414 9993104 213.7.62.154 (16 [27606]) X-Newsreader: Forte Free Agent 1.21/32.243 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Tue, 17 Apr 2001 16:59:54 +0200, Tim Van Holder wrote: > Michael Ahumibe wrote: > > > > Can someone tell me what's wrong? or if there is a work around. > > As said before fflush(stdin) isn't supposed to clear the input; I > believe > that's a Borlandism (or a Microsoftism, or both). > > But IIRC you can use the '%*c' specifier to read any number of > characters > (effectively clearing the input), without placing them into memory. > > So scanf ("%d%*c", &age) should read '20' into age and discard the rest. No. Fortunately this isn't true. If %*c would mean "read any number of characters" it would prompt eternally for input until EOF... %*c would read and discard one character only because this syntax is equivalent to %*1c. And the problem is that it would prompt for input if no character is available. A correct procedure to throw trailing input and leave the terminating \n in the stream is int test; test=scanf("%d", &age); scanf("%*[^\n]"); /* throw anything beyond what could be read. Stop reading and throwing in front of \n */ /* if test == 1 then the input line started with a valid int, otherwise age's value won't change */ Regards Horst