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

Recommended Answers

All 5 Replies

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.

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

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

>then I might have to suffer a non-standardized design, which isn't a big deal
then use getch

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() .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.