delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/06/14:51:49

From: Bojan Resnik <resnikb AT eunet DOT yu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: getch() with DJGPP
Date: Thu, 06 Apr 2000 17:54:50 +0200
Organization: Public news server of EUnet Yugoslavia
Lines: 23
Message-ID: <IrDsOIvS7ySyCgE0v0RVsbiyKTXe@4ax.com>
References: <38EC822B DOT 230D4ECE AT cafeetje DOT nl>
NNTP-Posting-Host: p-2.65.eunet.yu
Mime-Version: 1.0
X-Trace: SOLAIR2.EUnet.yu 955036686 23940 213.240.2.65 (6 Apr 2000 15:58:06 GMT)
X-Complaints-To: abuse AT EUnet DOT yu
NNTP-Posting-Date: 6 Apr 2000 15:58:06 GMT
X-Newsreader: Forte Agent 1.6/32.525
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Bart Verbakel <B DOT Verbakel-ab AT student DOT fontys DOT nl> wrote:

>I am trying to create a loop like this:
>
>while ( getch() != 'q' )
>  printf("Neverending textstring");
>
>This is SUPPOSED to put the string to stdout,
>until I touch the 'q' key.
>
>But, compiling this with DJGPP and running it in an DOS-box
>under Win98, It does not!!
>After each 'printf' it waits for me to press "RETURN"
>
>How do I solve this problem ???

  You misunderstood the getch() function. If a character is waiting in the
keyboard queue, it will return it. If it isn't, then it will wait until you
press a key.
  The way to accomplish what you want is to use kbhit():

  while ( !kbhit() || (getch() != 'q') )
     printf("Neverending textstring");

- Raw text -


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