How to hide characters from being displayed on screen as they are keyed in?

Posted by Tarek N. Elsamni | Posted in | Posted on 11:00

0

As has been mentioned, standard C keyboard input routines (getc, fgets, scanf, etc.) buffer the input until you press "Enter" --- and they echo each character as its key is pressed.

Old-style DOS functions like getch() are still available in certain Windows command-line application compilers (such as Borland C, for example). getch() returns the character to the calling program but doesn't echo it to the screen.

Here is a routine that I picked up somewhere some time ago (sorry, I didn't record the source, but I am quite sure I didn't delete any copyright notice). If it turns out that it is copyrighted or patented or something: let me know.

I compiled and executed it on my Linux system, and also on my windows system (using CYGWIN gcc). Output looks the same.

Here's the function, called linux_getch():



Here's a test program for linux_getch():


Comments (0)

Post a Comment