From: "Fred" Newsgroups: comp.os.msdos.djgpp Subject: getch() problems please help Date: Thu, 20 Nov 1997 13:28:34 +1100 Organization: ANS Communications Pty Ltd Lines: 65 Message-ID: <879992901.96859@gigi.ans.com.au> NNTP-Posting-Host: gigi.ans.com.au Cache-Post-Path: gigi.ans.com.au!unknown AT 203 DOT 56 DOT 162 DOT 33 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Hi, I'm using DJGPP in a win95 dos box. /* getchar input routine */ #include #include main() { char input[20]; int i = 0; cprintf ("You:"); while (input[i - 1] != 13) { if (input[i - 1] == 8) { i--; } if (i == 19) { cprintf("\b"); i = 18; } input[i] = getch(); cprintf("%c", input[i]); i++; } input[i] = 0; printf ("\n%s", input); } Okay, what I'm 'trying' to accomplish here is get a string from the user. I'm having trouble with the backspace part: if (input[i - 1] == 8) { i--; } It is a little hard to explain what happens when I run it, so if you could compile and run it yourself, you will get a better idea of what the problem is. Basically, if you type in a few chars, backspace a few, type more, eventually it will stop allowing you to type more chars, as it should with the: if (i == 19) { cprintf("\b"); i = 18; } which just makes the character overwrite itself when you have reached the limit of the input[] array. However if you use backspaces in the dos box, it might start doing this after only about 5 characters have been displayed. However the output shows that it has been taking in what you have been typing as the input[] array contains the 19 chars as it should. Any ideas?