943,816 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 4712
  • C++ RSS
Sep 18th, 2006
1

using scanf without pressing ENTER

Expand Post »
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
Similar Threads
Reputation Points: 50
Solved Threads: 0
Junior Poster in Training
Diode is offline Offline
70 posts
since Jan 2005
Sep 18th, 2006
1

Re: using scanf without pressing ENTER

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.
Moderator
Reputation Points: 3278
Solved Threads: 892
Posting Sage
WaltP is offline Offline
7,718 posts
since May 2006
Sep 18th, 2006
1

Re: using scanf without pressing ENTER

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
Reputation Points: 50
Solved Threads: 0
Junior Poster in Training
Diode is offline Offline
70 posts
since Jan 2005
Sep 18th, 2006
0

Re: using scanf without pressing ENTER

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
Reputation Points: 50
Solved Threads: 0
Junior Poster in Training
Diode is offline Offline
70 posts
since Jan 2005
Sep 18th, 2006
1

Re: using scanf without pressing ENTER

>then I might have to suffer a non-standardized design, which isn't a big deal
then use getch
Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 2005
Sep 18th, 2006
0

Re: using scanf without pressing ENTER

Click to Expand / Collapse  Quote originally posted by Diode ...
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().
Moderator
Reputation Points: 3278
Solved Threads: 892
Posting Sage
WaltP is offline Offline
7,718 posts
since May 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: text editor
Next Thread in C++ Forum Timeline: Help with derived class and arithmetic in C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC