www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/10/16/17:57:52

Date: Mon, 16 Oct 2000 23:52:33 +0200
From: "Eli Zaretskii" <eliz AT is DOT elta DOT co DOT il>
Sender: halo1 AT zahav DOT net DOT il
To: djgpp AT delorie DOT com
Message-Id: <9003-Mon16Oct2000235232+0300-eliz@is.elta.co.il>
X-Mailer: Emacs 20.6 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.5h
In-reply-to: <87og0k5w18.fsf@pfaffben.user.msu.edu> (message from Ben Pfaff on
16 Oct 2000 17:13:55 -0400)
Subject: Re: Undertaking a programming journey
References: <MOqE5.2173$W31 DOT 29870 AT news1 DOT online DOT no> <8scg36$gsm$1 AT nnrp1 DOT deja DOT com> <39E9CF07 DOT 785C0C0F AT eton DOT powernet DOT co DOT uk> <8scls9$kth$1 AT nnrp1 DOT deja DOT com> <rgnjusgvadc5q9d53jticrrgdthc9af3lv AT 4ax DOT com> <39E9FAD5 DOT DE1FDAE4 AT eton DOT powernet DOT co DOT uk> <8sdrub$h7u$1 AT nnrp1 DOT deja DOT com> <39EAA40B DOT 31B0CA89 AT eton DOT powernet DOT co DOT uk> <8seoli$65v$1 AT nnrp1 DOT deja DOT com> <39EAF73E DOT ECA52E1A AT antlimited DOT com> <8sfbu7$n06$1 AT nnrp1 DOT deja DOT com> <39EB4271 DOT 85CE6874 AT antlimited DOT com> <8sfhr4$si2$1 AT nnrp1 DOT deja DOT com> <carmus46p99htn74ttv2k5qrsclqbnj26u AT 4ax DOT com> <87og0k5w18 DOT fsf AT pfaffben DOT user DOT msu DOT edu>
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

> From: Ben Pfaff <pfaffben AT msu DOT edu>
> Newsgroups: alt.comp.lang.learn.c-c++,comp.os.msdos.djgpp,comp.programming
> Date: 16 Oct 2000 17:13:55 -0400
> 
> Damian Yerrick <Bullcr_pd_yerrick AT hotmail DOT comRemoveBullcr_p> writes:
> 
> > For the record, what's the "right" way to clear an input buffer?
> 
> Here's one "right" way, assuming that you mean "skip input up to
> the end of the line":
> 
> for (;;) {
>   int c = getc (stream);
>   if (c == '\n' || c == EOF)
>     break;
> }

IMHO, this is not a very good method: depending on system-dependent
buffering, this could become stuck inside the call to getc.

It is much better, in my experience, to simply fseek the stdin stream
to a sufficiently large negative offset.  All implementations I've
seen will throw away buffered characters in this case.

Termios has a special function tcflush to discard characters pending
on a given file handle.  This doesn't empty the characters buffered
inside a FILE object, though, but you could use tcflush in addition to
the fseek trick, to really empty everything.

- Raw text -


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