cvs.gedasymbols.org/archives/browse.cgi | search |
From: | tdavis AT gearbox DOT maem DOT umr DOT edu (Ted Davis) |
Newsgroups: | comp.os.msdos.djgpp,comp.os.msdos.programmer |
Subject: | Re: Iteration vs. Recursion... |
Date: | Fri, 23 Jul 1999 13:08:17 GMT |
Message-ID: | <379967a5.66626423@news.cc.umr.edu> |
References: | <7n7s1h$ms6$1 AT autumn DOT news DOT rcn DOT net> |
X-Newsreader: | Forte Agent 1.5/32.452 |
MIME-Version: | 1.0 |
NNTP-Posting-Host: | ted-nt.maem.umr.edu |
X-Original-NNTP-Posting-Host: | ted-nt.maem.umr.edu |
X-Trace: | 23 Jul 1999 08:08:18 -0600, ted-nt.maem.umr.edu |
Organization: | University of Missouri - Rolla |
Lines: | 73 |
To: | djgpp AT delorie DOT com |
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
Reply-To: | djgpp AT delorie DOT com |
On Thu, 22 Jul 1999 14:24:32 -0400, "Tom" <thomasbd AT erols DOT com> wrote: >I have a keyboard input program that runs one thing if one key is entered >and another if another key is entered. There are about ten different >options. That means I have ten different if statements. I am using >recursion because after I get one input I do the program over again. > >The only problem with this program is that I have to hold down the key for >about a second before anything is recognized. Is there any way to speed >this up? Possibly by using iteration instead of recursion. Here is the >code. Any suggestions are greatly appreciated. I left out the program >names and variables not needed. I use getch to catch the keystrokes. I >tried using the bioskey but that didn't speed anything up. I am using DJGPP >to compile this: > >/*********start code******** > >{ >if (getch() == x) >{run_program(); >run_program(); >exit(0);} >if (getch() == y) >run_program(); >if (getch() == z) >run_program(); >if (getch() == a) >run_program(); >if (getch() == b) >run_program(); >if (getch() == c) >run_program(); >if (getch() == d) >run_program(); >if (getch() == e) >{run_program(); >if ((getch() == f || (getch() == g)) >run_program(); >if (getch() == h) >run_program(); >if (getch() == i) >run_program(); >} > >****end code**********/ > >Thanks. > >Tom > Duh... getch() pauses and waits for a key before returning - to get to the last IF test, you have to hold the key down long enough for the typmatic repeats to load as many copies of the key as there are IFs into the buffer. foo = getch() then if(foo==pattern) repeated as many times as needed will wait until exactly one key is pressed, then apply all the tests to the copy placed in the variable. Don't forget that if getch() retruns 0, you have to call it again or there will be a partial character left over to be tested on the next pass. This leads to incorrect key recognition. T.E.D. (tdavis AT gearbox DOT maem DOT umr DOT edu) SPAM filter: Messages to this address *must* contain "T.E.D." somewhere in the body or they will be automatically rejected.
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |