Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 1st, 2005, 11:55 AM   #1
hipolito
Programmer
 
Join Date: Feb 2005
Posts: 41
Rep Power: 0 hipolito is on a distinguished road
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.
hipolito is offline   Reply With Quote
Old Mar 1st, 2005, 2:26 PM   #2
spydoor
Programmer
 
Join Date: Feb 2005
Posts: 64
Rep Power: 4 spydoor is on a distinguished road
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
spydoor is offline   Reply With Quote
Old Mar 1st, 2005, 4:05 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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;
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 2nd, 2005, 5:30 AM   #4
hipolito
Programmer
 
Join Date: Feb 2005
Posts: 41
Rep Power: 0 hipolito is on a distinguished road
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.
hipolito is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:46 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC