Back Spacing

This is a discussion on Back Spacing within the C++ Programming forums, part of the General Programming Boards category; Hi.. I am building a program where i use getche to get an input from the user.. how do i ...

  1. #1
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683

    Back Spacing

    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

  2. #2
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    The character for backspace I believe is '\b'. You could always make a program that does
    Code:
    char a = getche();
    cout << int(a);
    If you press spacebar the output will be the ascii value of spacebar.

  3. #3
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    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.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    16
    wuile we are on this topic how would you go about deleting a space... instead of backspaceing??

  5. #5
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    What???

  6. #6
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    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.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    16
    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.

  8. #8
    Unregistered
    Guest
    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];
    }

  9. #9
    Registered User Aran's Avatar
    Join Date
    Aug 2001
    Posts
    1,301
    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.

  10. #10
    Registered User toaster's Avatar
    Join Date
    Apr 2002
    Posts
    161
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Back to the drawing board
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 03-08-2004, 04:53 PM
  2. "if you love someone" :D
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 10-02-2003, 01:10 AM
  3. UInt to CString and back
    By xlnk in forum Windows Programming
    Replies: 6
    Last Post: 08-27-2003, 03:08 PM
  4. Some woman back ended my car today, and back hurts
    By Terrance in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 08-20-2003, 12:42 AM
  5. Returning a Tree node back to void main()
    By gazza in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2002, 02:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21