Mail Archives: djgpp/1997/11/19/22:01:33
Hi,
I'm using DJGPP in a win95 dos box.
/* getchar input routine */
#include <stdio.h>
#include <CONIO.h>
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?
- Raw text -