R
RajW
Disclaimer: I'm new to C.
I'm building a simple text based program and I'm not sure I'm
designing it correctly. What I have is simple and it works but it just
seems weird. Is there a better way? I do still have some debugging
code in the subroutine to print out the key pressed.
Basically menuinput() waits for the key press, and passes it to the
switch below. What I'm confused about is, what is the best way to get
back to the menu input subroutine? At the end of the routine that was
called, should I just call menuinput() again?
Thanks,
/*Raj*/
--------------------
Here is the menu input subroutine:
<code>
int menuinput() {
unsigned char menukey;
fflush (stdout);
menukey = getc();
gotoxy (12,18);
printf("key pressed: %c", menukey);
sleep(3);
clearxy(12,18, 16);
switch(menukey)
{
case 'a':
drstatus();
break;
case 'b':
resetdr();
break;
default:
putsxy(1, 20, "invalid menu option");
sleep(3);
clearxy(1, 20, 20);
menuinput();
break;
}
}
</code>
I'm building a simple text based program and I'm not sure I'm
designing it correctly. What I have is simple and it works but it just
seems weird. Is there a better way? I do still have some debugging
code in the subroutine to print out the key pressed.
Basically menuinput() waits for the key press, and passes it to the
switch below. What I'm confused about is, what is the best way to get
back to the menu input subroutine? At the end of the routine that was
called, should I just call menuinput() again?
Thanks,
/*Raj*/
--------------------
Here is the menu input subroutine:
<code>
int menuinput() {
unsigned char menukey;
fflush (stdout);
menukey = getc();
gotoxy (12,18);
printf("key pressed: %c", menukey);
sleep(3);
clearxy(12,18, 16);
switch(menukey)
{
case 'a':
drstatus();
break;
case 'b':
resetdr();
break;
default:
putsxy(1, 20, "invalid menu option");
sleep(3);
clearxy(1, 20, 20);
menuinput();
break;
}
}
</code>