Hi.. I am building a program where i use getche to get an input from the user.. how do i represent back space.. That is if the user presses the back space button...
Thanx
Vasanth
Hi.. I am building a program where i use getche to get an input from the user.. how do i represent back space.. That is if the user presses the back space button...
Thanx
Vasanth
The character for backspace I believe is '\b'. You could always make a program that does
If you press spacebar the output will be the ascii value of spacebar.Code:char a = getche(); cout << int(a);
I didn't think it was possible to check for escape sequences in relation to a key press, such as "\b". The ascii code for backspace is 8 AFAIK.
Code:#include <conio.h> #include <iostream.h> int main () { clrscr(); char key = getch(); if (int(key)==8) { cout << "Your Pressed Backspace\n"; } else { cout<<"You didn't press backspace, they ascii code for the key you pressed was "; cout<<int(key); } return 0; }
Last edited by Azuth; 04-25-2002 at 01:45 AM.
wuile we are on this topic how would you go about deleting a space... instead of backspaceing??
I don't think I fully understand you.
you mean to go back one space when an user inputs backspace or to store the value of backspace when an user inputs backspace?
to show backspace, there are examples posted above.
to store it, use a string,array,vector,pointer...
like:
some_array[some_position_in_array] = '\b';
think only with code.
write only with source.
Ok sorry... what i meant was.....
A backspace deletes spaces to the left....
however 'delete' deletes spaces to the right...
you explained here how to use a backspace...
i was asking if there was a delete command or something that i could use to delete spaces to the right..
Last edited by CARBUNCLE; 04-27-2002 at 10:59 AM.
I know there are far more better methods than this but you can do something that can shift values to the left:
for( ; i<length_of_array; i++)
{
array[array_position] = array[array_position + 1];
}
you would lose a value or two in the array using that, and you would also write over the bounds of the array. Once it hits length_of_array it'll be writing to length_of_array+1 which is out of bounds.
oops, I did it in a hurry.
of course, I forgot to put in the error traps.
but if you want to use something like delete, that is a solution.
change the (length_of_array) to (length_of_array - 1)
and then out of the loop, add:
array[position_in_array] = NULL;
sorry about that.
Last edited by toaster; 04-27-2002 at 11:19 AM.
think only with code.
write only with source.