[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Flushing af stdin



On Tue, 30 May 2000 00:41:27 +0200 (CEST), Mads Bondo Dydensborg wrote:
>On Mon, 29 May 2000, Peter Seidler wrote:
>
>> Hej
>> 
>> Kunne en eller anden venlig sjæl fortælle mig, hvordan man flusher stdin.
>> Jeg læser med et bestemt interval det første tegn fra stdin. Derefter vil
>> jeg gerne flushe den.
>> Når jeg så venter en stykke tid og læser igen, kan jeg altså være sikker på,
>> at det tegn jeg læser er tastet i det tidsrum, hvor programmet har sovet.
>> fflush(stdin) virker ikke, men stdin er vel heller ikke en output / updtate,
>> men en input stream.
>
>Jeg tror du skal prøve at forklare os hvad du vil, for det giver ikke
>umiddelbart mening at "flushe" stdin.

Ok så,

----------

int ch;

for (;;) {
	/* Det første tegn indtastet i løbet af de sidste 2 sek. læses. */
	ch = getchar();
	
	/* Her flusher vi så stdin. (Det ville vi i hvert fald gerne). */

	/* Og så sover vi mens stdin måske fyldes lidt op igen. */
	sleep(2);
}

----------

Og det er meget muligt, det ikke giver mening, men er det muligt?
En eller anden foreslog:

	if (ch != EOF)
		while (getchar() != EOF)

og det er sådan set præcis det jeg gerne vil - bare med et enkelt kald.
Hvis man ikke kan det bruger jeg bare ovenstående.

--
	Peter Seidler

>
>Mads
>
>-- 
>Mads Bondo Dydensborg.                               sslug@sslug
>The point is to decide what your needs are, pick an editor that looks like
>it may fit them and then MASTER it. Learn every little nuance and key
>stroke. Not just the easy stuff you pick up in an hour or two but especially
>the obscure stuff. Learn it so well that your mind can stay about two steps
>ahead of hands even when using the arcane commands and keystrokes. Then you
>can edit in front of crowds and people will ohh and awe. Source code will
>fear you. Project managers will want you. 
>                                        - Dana S. Wheeler, M.D. on emacs/vi
>


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *