Is there a function that would allow me to check the characters when they key is pressed....before the enter key?

I am coding a program that requieres the user to enter only letters (from A to Z && a to z), but I want to check each character when it's being entered.

11 Years
Discussion Span
Last Post by red

There's no standard way (C and C++ are line oriented), so you'll need to tell us your compiler and operating system.


Yes, but you can't do them portably. If you are using borland or visual C++ compilers you can try the getch() or getche() function to do that.


Whoa! you guys are fast, one minute ago there were no reply and now two posts in between the red's first and mine.

To red:
I can use getch() or getche() in gcc that comes with MinGW, so you should be able to do that in Dev C++ too.


Thanks to both of you,

What library do I need to include for the getch() and getche() functions? I tried them both but the compiler is telling me that those functions are not defined. All I am including is the <iostream>.


Those are non-standard C functions that are defined in conio.h. Because they are non-standard, they may not be supported by all compilers (I think Dev-C++ supports them)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.