| delorie.com/archives/browse.cgi | search |
| From: | locke AT mcs DOT net (Peter Johnson) |
| Newsgroups: | comp.os.msdos.djgpp,comp.os.msdos.programmer |
| Subject: | Re: Iteration vs. Recursion... |
| Date: | Thu, 22 Jul 1999 20:40:56 GMT |
| Organization: | BiLogic Productions |
| Lines: | 66 |
| Message-ID: | <37978194.17661031@news.cso.uiuc.edu> |
| References: | <7n7s1h$ms6$1 AT autumn DOT news DOT rcn DOT net> |
| NNTP-Posting-Host: | rochester-25.slip.uiuc.edu |
| Mime-Version: | 1.0 |
| X-Newsreader: | Forte Agent 1.5/32.452 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Do something like the following:
switch(getch()) {
case x: run_program1();
break;
case y: run_program2();
break;
...
}
Read up on switch statements in your favorite C reference book :).
Peter Johnson
locke AT mcs DOT net
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
>
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |