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.

Recommended Answers

All 7 Replies

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

Dev-C++ and WindowsXP.

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)

Thanks, I got it.

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.