Hi There.
I'm making a routine in C that reads a simple int. I want this routine to allow ESC key, so when the user changes his/her mind about continuing entering digits, he or she can press ESC to exit this routine.
I have been searching in this site all the way around, and seems that there's no way Hard to beleive! I have studied getch(), getc() getchar(), etc.. as well as kbhit(), nothing seems to work. does anyone of you genious have any idea?
Here's what I have so far:
int ReadNumber( int *number) {
/* modifies it's argument depending on what number the user types, if the user change his/her mind he/she can press ESC and the function returns 1 if so, otherwise, it returns 0 */
{
char c,digit;
char strnumber[10];
int i=0;
printf("Enter your number (ESC to quit) :");
do {
c = (char) getch();
if ( is_a_digit(c, *digit) ) {
strnumber[i++] = digit;
}
else { c = int(c);
switch(c) {
case 8 : /* backspace bla bla */
break;
.
.
.
} /* switch */
} /* else */
} while (c !=27);
strnumber[i] = '/0' /* sorry couldn't find the backslash in this machine */
*number = atoi(strnumber);
return(0);
}
int is_a_digit (char c, char *dig) {
/* assume this returns 1 if c is a digit, and if so puts it in *dig, otherwise return 0 . Could you do that for me, thanks */
}
I run it but when the user types ESC, I have a little arrow on the screen (pointing to the left).
Is there any other way to catch digit by digit to analyse them?
I'm working with Dev-C++, windows 98, pentium processor.
Thanks in advance.
Gustaff.