using scanf without pressing ENTER

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2005
Posts: 70
Reputation: Diode is on a distinguished road 
Solved Threads: 0
Diode's Avatar
Diode Diode is offline Offline
Junior Poster in Training

using scanf without pressing ENTER

 
1
  #1
Sep 18th, 2006
Hello,

I am trying to develop something that, when you press a character on the keyboard, puts a char into a char-type variable. Should be easy right? Well, I don't want to require the user to have to press ENTER when they press the key. Maybe scanf isn't the right function to use ( it's C ), but I want it to work the same way as if you're reading a file in UNIX with the 'LESS' command, and you hit 'q' to quit; you don't have to hit ENTER. It automatically knows you pressed 'q'.

How do I program for that? I don't know how to without using scanf to get a value. And, um, I don't want to use scanf.

Thanks,
Diode
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,117
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 282
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: using scanf without pressing ENTER

 
1
  #2
Sep 18th, 2006
You can't in Standard C. Some compilers have special functions that are not portable that can accomplisht what you want, but it's generally different for each compiler. So, if you want to enter the realm of non-standardization, we need more info.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 70
Reputation: Diode is on a distinguished road 
Solved Threads: 0
Diode's Avatar
Diode Diode is offline Offline
Junior Poster in Training

Re: using scanf without pressing ENTER

 
1
  #3
Sep 18th, 2006
Ok,

I'm using the Dev-C++ 4 compiler along with gcc.

I would have preferred it to be standard C, but since you informed me that it cannot be done with standard C, then I might have to suffer a non-standardized design, which isn't a big deal, I just kind of wanted to take it to any platform I wanted. Right now though, I'm just programming for Windows.

What I'm programming is a text-based RPG. Anyway, how can I do it in a non-standardized way?

Thanks,
Diode
Reply With Quote Quick reply to this message  
Join Date: Jan 2005
Posts: 70
Reputation: Diode is on a distinguished road 
Solved Threads: 0
Diode's Avatar
Diode Diode is offline Offline
Junior Poster in Training

Re: using scanf without pressing ENTER

 
0
  #4
Sep 18th, 2006
Would you suggest that I use getch() found in conio.h and convert it to C++ instead? I could do that, I just wanted to go old-school for fun, but whatever works.

Thanks,
Diode
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: using scanf without pressing ENTER

 
1
  #5
Sep 18th, 2006
>then I might have to suffer a non-standardized design, which isn't a big deal
then use getch
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,117
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 282
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: using scanf without pressing ENTER

 
0
  #6
Sep 18th, 2006
Originally Posted by Diode View Post
Ok,

I'm using the Dev-C++ 4 compiler along with gcc.

I would have preferred it to be standard C, but since you informed me that it cannot be done with standard C, then I might have to suffer a non-standardized design, which isn't a big deal, I just kind of wanted to take it to any platform I wanted. Right now though, I'm just programming for Windows.
In that case, getch() is your function. Also look into kbhit(), if Dev-C has it. It's extremely useful with getch().
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC