www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/09/07/06:24:34

From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: simple getch()
Date: Fri, 06 Sep 2002 21:23:50 +0100
Lines: 38
Message-ID: <3D790ED6.78499A07@phekda.freeserve.co.uk>
References: <wa7e9.146658$Rx4 DOT 1541323 AT twister DOT tampabay DOT rr DOT com>
NNTP-Posting-Host: modem-105.doxycycline.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: news7.svr.pol.co.uk 1031388941 2816 62.136.91.105 (7 Sep 2002 08:55:41 GMT)
NNTP-Posting-Date: 7 Sep 2002 08:55:41 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.19 i586)
X-Accept-Language: de,fr
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hello.

MrShifty wrote:
> 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. I know it has to be
> somehting simple. Any help is appreciated. If this is the wrong newsgroup
> please point in the direction of a Windows specific newsgoup.
> 
> Here is the code:
> 
> #include <iostream.h>
> #include <conio.h>
> 
> int main(){
>  int ch;

ch is uninitialised. Try:

   int ch = 0;

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

Maybe you should compile with the -Wall option, e.g.:

    gcc -c -Wall ...

Regards,

-- 
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]

- Raw text -


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