X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Martin Ambuhl Newsgroups: comp.os.msdos.djgpp Subject: Re: Function kbhit()? Date: Tue, 20 Jul 2004 03:42:09 -0400 Lines: 60 Message-ID: <2m40mjFhp3nlU1@uni-berlin.de> References: <2m3hjoFibqajU1 AT uni-berlin DOT de> <7494-Tue20Jul2004073651+0300-eliz AT gnu DOT org> <2m3odtFhufc2U1 AT uni-berlin DOT de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de PuXQKh4vCs0U4DS1lgobPAaCAXGG7wVK8a7JAvyqs81HZUmPjf User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040616 X-Accept-Language: en-us, en, de, fr, ru, zh, ja In-Reply-To: <2m3odtFhufc2U1@uni-berlin.de> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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 Precedence: bulk Fausto Arinos de A. Barbuto wrote: > "Eli Zaretskii" wrote in message > news:7494-Tue20Jul2004073651+0300-eliz AT gnu DOT org... > >>>From: "Fausto Arinos de A. Barbuto" >>>Newsgroups: comp.os.msdos.djgpp >>>Date: Mon, 19 Jul 2004 21:24:39 -0600 >>> >>> I am porting an old C code to GCC. It works very well with Borland C 3.1 >>> and although it compiles and runs with gcc, it doesn't work as intended. >>> After much tinkering with the code, I found out that the problem is in a >>> statement that contains the kbhit() function. GCC didn't complain about >>> it during compilation though, hence I assume that kbhit() exists in GCC >>> -- it is I who can't use it properly. Any hints? Your help will be very much >>> appreciated. > > >>Yes, DJGPP does have kbhit. But without seeing the code and knowing >>what exactly do you mean by ``doesn't work as intended'' it is hard >>to tell what is wrong. > > > Thanks for replying, Eli. The piece of code where kbhit() is being used is a > short function, as shown below: > > void check_event(int *key) > { > while (kbhit()) getch(); > *key = bioskey(0); > } > > Called at this program segment: > > [...] > check_event(&cmd); > p = toupper(cmd); > if (p == 'R') > return; > if (p == 'A') { > build_amort(v); > display_amort(); > factor_header(); > aflg = 0; > fflg = 1; > return; > } > [...] > > It should then (in theory) capture a keyboard hit, make it uppercase > and then decide what to do with the result. > > Now giving the code a closer look, it is quite possible that the error > is due to the function bioskey(). Maybe. > *Maybe* it's because when !kbhit(), you don't call getch() but you do store a value into *key. This meaningless value is then supplied to toupper() and assigned to p.