www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/09/07/17:15:18

From: "A. Sinan Unur" <asu1 AT c-o-r-n-e-l-l DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: simple getch()
Date: 7 Sep 2002 21:13:23 GMT
Organization: Cornell University
Lines: 54
Sender: asu1 AT cornell DOT invalid (on pool-141-149-206-20.syr.east.verizon.net)
Message-ID: <Xns9282AF356FBEAasu1cornelledu@132.236.56.8>
References: <wa7e9.146658$Rx4 DOT 1541323 AT twister DOT tampabay DOT rr DOT com>
NNTP-Posting-Host: pool-141-149-206-20.syr.east.verizon.net
X-Trace: news01.cit.cornell.edu 1031433203 1898 141.149.206.20 (7 Sep 2002 21:13:23 GMT)
X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu
NNTP-Posting-Date: 7 Sep 2002 21:13:23 GMT
User-Agent: Xnews/5.04.25
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"MrShifty" <mailmespamhere AT yahoo DOT com> wrote in
news:wa7e9.146658$Rx4 DOT 1541323 AT twister DOT tampabay DOT rr DOT com: 

> When I run this program it doesn't beep until I hit escape. At that
> point it beeps however many times that I hit the spacebar. 

cout is buffered by default. it is not a good idea to intermix conio 
functions with the standard library routines.

> Here is the code:
> 
> #include <iostream.h>
> #include <conio.h>
> 
> int main(){
>  int ch;
> 
>  while(ch != 27){

ch is unitialized in this test.


>   ch = getch();
>   if(ch == 32)
>    cout << '\a';
>  }
> 
>  return 0;
> }

try the following:

#include <conio.h>
#include <dpmi.h>

int main(void) 
{
	int c;
	while((c = getch()) != 27)
	{
		if(c == ' ')
		{
			putch('\a');
			__dpmi_yield();
		}
	}

	return 0;
}
-- 
A. Sinan Unur
asu1 AT c-o-r-n-e-l-l DOT edu
Remove dashes for address
Spam bait: mailto:uce AT ftc DOT gov

- Raw text -


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