1

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

3
Contributors
5
Replies
6
Views
10 Years
Discussion Span
Last Post by WaltP
Featured Replies
  • 1
    WaltP 2,905   10 Years Ago

    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. Read More

1

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.

1

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

0

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

1

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

0

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

This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.