| | |
using scanf without pressing ENTER
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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
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
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
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
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
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
•
•
•
•
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.
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
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- Help with strings/scanf in C (for newbie) (C)
- Pressing Enter on an empty string - Help (C++)
- makin a table (noob, please help) (C++)
Other Threads in the C++ Forum
- Previous Thread: text editor
- Next Thread: Help with derived class and arithmetic in C++
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






