Thread: Cursor position

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    147

    Cursor position

    I want to do something the following output :

    Please enter your selection : ( )



    i would like the user's input to be k eyed in between the 2 brackets, but how do i print the last closing bracket symbol and move the cursor position backwards?

    is this possible?
    Only by the cross are you saved...

  2. #2
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    If your compiler supports it, you could use gotoxy().

    It will set the cursor position to where ever you like, ex: gotoxy(35,59); Just set it one space back.

    --edit-- For something else, check out this faq.
    Last edited by stumon; 07-03-2003 at 06:28 AM.
    The keyboard is the standard device used to cause computer errors!

  3. #3
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    Or after p[rinting the ')' output a backspace (0x08) as many times as needed

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    If you are using Windows, part 2 of my tutorial here covers moving the cursor in a console.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    er.........adrianxw, ur tutorial mainly covers C++, so even the function or some classes involved in moving a cursor, are they valid in just C?

    waltp, er......the problem is by using the backspace, my ')' in '( )' also gets erased...

    not sure bout gotoxy, will try and see...
    Only by the cross are you saved...

  6. #6
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    >>> ur tutorial mainly covers C++,

    The only C++ features are that now I use cout etc. rather than printf(). I'm converting the old tutorials from C to C++ because many people asked me to. The functions and techniques used are exactly the same in C.

    gotoxy() is compiler specific. It will not work with MS compilers for example. The routines I use are Win32 API functions so as long as you include windows.h, should be independent of the compiler.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  7. #7
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    ok, thanx, i'll look into ur tutorial again...
    in the faq section, i pasted the function gotoxy defined there, into my program, and moved the cursor position, but it still deletes the ')' in '( )', so it is just like the backspace deleting it away...
    Only by the cross are you saved...

  8. #8
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    i tried ur tutorial adrianxw...

    this is just a snip from my code :

    printf ("Please enter your menu selection number :\t( )");

    position.X = 49;
    position.Y = 24;
    SetConsoleCursorPosition(hOut,position);
    printf ("t");


    when i print t, it appears after '(', but the program stops there, without displaying ')' after 't'

    could it look like '(t)' instead?
    Only by the cross are you saved...

  9. #9
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    okok, it works now thanx...
    Only by the cross are you saved...

  10. #10
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Compile this.
    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main()
    {
        HANDLE hOut;
        COORD Where;
    
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
        printf("Put the t in the brackets ( )");
    
        Where.X = 27;
        Where.Y = 0;
    
        SetConsoleCursorPosition(hOut,
                                 Where);
    
        printf("t");
    
        Where.X = 0;
        Where.Y = 1;
    
        SetConsoleCursorPosition(hOut,
                                 Where);
        return 0;
    }
    *** EDIT ***
    Okay! Parallelism there!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  11. #11
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    thank you so much adrianxw, ur tutorial was also very helpful!
    Only by the cross are you saved...

  12. #12
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    waltP, u mentioned that the code for backspace is 0x08, wat about for delete?
    Only by the cross are you saved...

  13. #13
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    or, the ANSI code for it...

    is there anyway in C where I can convert to the ansi code so i know wat number represents stuff like backspace, or a delete, space, character and so forth?
    Only by the cross are you saved...

  14. #14
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    There is an ascii table here. DEL is 0x7F.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  15. #15
    Registered User
    Join Date
    Jun 2003
    Posts
    147
    password[i]=getch();
    if (password[i]==13)
    ...
    else if (password[i]==8)
    ...
    else if (password[i]==127)
    ...
    else
    printf("*");

    8 is for backspace, 13 is for enter, and 127 is for delete
    the problem is while the backspace thing works, when i press the delete ke y

    it seems to execute the printf("*") instead of entering the ==127 else if statement...in fact, it prints '**' for every single time i press the delete key...
    does getch() have a problem witht he delete key??????/
    Only by the cross are you saved...

Popular pages Recent additions subscribe to a feed