Search code examples
cdosturbo-c

backspace and delete issues with the getch() function in DOS


I am using the Turbo C compiler on a Windows platform, Intel x86 architecture.

In my program I am scanning user input from the keyboard. It is a login password program that takes in username and password as user inputs.

For the username I am using getchar(), where while entering the username if the user presses the backspace key, on the keyboard, the previous character gets deleted, on it's own, I mean I don't need to write any explicit code to do this.

But for the password I am using getch() and corresponding to every keystroke I am displaying a * on the screen. In this case if user presses the backspace key on the keyboard, it does not delete the previous character, but rather takes it as another key stroke and displays a * corresponding to it on the screen.

I tried out bioskey from bios.h, tried using \b to work around, none worked.

Any suggestions or workarounds....????


Solution

  • Sure. Keep track of the characters for yourself. If your program is receiving the backspace so that it displays a *, then check for that character and back up one space. After backing up one space, print a space to erase the *, then back up again.