![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Feb 2005
Posts: 41
Rep Power: 0
![]() |
Exiting problem
Hi all, again...
Well I got this part of the code: do { printf("Valor corrente: %f\n",anarec.curval); sleep(3); ch = getch(); } while (ch!='q' && ch!='Q'); exit(0); What I want to do is when the "q" key is pressed the program just quit, but using this getch() the user must hit ENTER after pressing "q". How do I fix the program so the user just hit the "q" key to exit?? Thanks for your help. |
|
|
|
|
|
#2 |
|
Programmer
Join Date: Feb 2005
Posts: 64
Rep Power: 4
![]() |
I'm no expert, but I'm under the impression there is no great way to accomplish this.
If on a unix system you could try something like. system("stty raw");
while (ch!='q' && ch!='Q');
system("stty -raw");also search for curses.h or conio.h if for DOS |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
With getch(), you shouldn't have to press Enter after pressing "q" - are you sure you're using it right? And don't use exit; use return.
do {
printf("Valor corrente: %f\n", anarec.curval);
sleep(3);
}
while ((getch() | 0x20) != 'q');
return 0; |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Feb 2005
Posts: 41
Rep Power: 0
![]() |
yo spydoor,
that worked just fine, thx a lot. The only thing is, using this raw mode my output is beeing tabed, but it works. oh yeah. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|