Mail Archives: djgpp/1996/04/27/22:45:44
I had a program that sits in a loop and gets and prints input using the
cgets/cprintf functions. When I would hit an arrow key, it would seem as
if cgets stops taking input, and after a few seconds I would get a
"general protection" error and the program would crash. This small
program, although it doesn't cause a GPF (it was probably some other
part of my program that caused it) does show that cgets(), once it gets
an arrow key, continues "getting" some kind of input, and stops when it
reaches the maximum characters specified, and when cgets() is called
again, it still gets the same garbage, and so on.
==begin==
#include <conio.h>
#include <stdio.h>
int main()
{
char input[10];
input[2] = 'a'; /* to fool while first time around */
input[0] = 5; /* cgets() uses this to know max chars to read */
cprintf("Enter a max of 4 characters, 0 to stop.\r\n");
cprintf("\r\n(Push the up arrow to see bug (?))\r\n");
while(input[2] != '0') { /* first char input is in third element */
cgets(input);
cprintf("\r\nYou entered: %s\r\n", input + 2);
}
return 0;
}
==end==
Run this and you'll see the problem.
Good day,
YL
- Raw text -