Positioning the cursor where I want it?

This is a discussion on Positioning the cursor where I want it? within the C++ Programming forums, part of the General Programming Boards category; I want to be move the cursor to any place I want ont he screen and then output text at ...

  1. #1
    Registered User SPiRiToFCaT's Avatar
    Join Date
    May 2002
    Posts
    35

    Question Positioning the cursor where I want it?

    I want to be move the cursor to any place I want ont he screen and then output text at that position.

    For example, I want an "*" 5 lines down and five spaces to the right on a standard DOS screen, does anyone here know how I can do it?

    I remember I could do it in Pascal with the gotoxy() command.

    Thanks in advance.
    - Well that's my 4c Australian.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Borland compilers have a gotoxy() function in conio.h and you can simulate this effect in a Windows environment with
    Code:
    #include <windows.h>
    void gotoxy(int x, int y)
    {
       COORD coord;
       coord.X = x;
       coord.Y = y;
       SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User SPiRiToFCaT's Avatar
    Join Date
    May 2002
    Posts
    35
    Thanks, I'll have a look at the gotoxy() in conio.h and then if that doesn't work I'll try the windows.h thing.

    I'm using a compiler I got from my Univertsity since we are learning C++ there, it's called Bloodshed Dev-C++
    - Well that's my 4c Australian.

  4. #4
    Registered User SPiRiToFCaT's Avatar
    Join Date
    May 2002
    Posts
    35
    THANK YOU!

    I tried including conio.h but that didn't get me a gotoxy() function.
    So I tried the code you wrote and it worked fine!

    Ummm, since it's using windows.h, if I tried to compile this in a Unix system, what would happen?
    - Well that's my 4c Australian.

  5. #5
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225

    Talking

    Obviously there would be errors hehehe.

    But I think there's somekinda conio.h in Unix or something like that (I have no Unix, only Bill Gates' pet software).
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >if I tried to compile this in a Unix system, what would happen?
    Well, it kind of wouldn't work. To do this in a Unix system you can use curses:
    Code:
    #include <curses.h>
    
    int main ( void )
    {
      initscr();
      move ( 5, 5 );
      addch ( '@' );
      refresh();
      endwin();
      return 0;
    }
    -Prelude
    My best code is written with the delete key.

  7. #7
    Registered User SPiRiToFCaT's Avatar
    Join Date
    May 2002
    Posts
    35
    Okay, I see now, cool.

    Thanks for your help!
    - Well that's my 4c Australian.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Trouble in positioning myself into OOP way...!
    By patil.vishwa in forum C++ Programming
    Replies: 4
    Last Post: 09-19-2008, 06:19 AM
  2. Positioning in a circular pattern?
    By arcaine01 in forum C# Programming
    Replies: 1
    Last Post: 05-01-2008, 12:26 AM
  3. Positioning Message Box MFC
    By UnclePunker in forum Windows Programming
    Replies: 2
    Last Post: 08-12-2004, 04:14 AM
  4. Relative positioning
    By Unregistered in forum Game Programming
    Replies: 7
    Last Post: 05-14-2002, 12:00 AM
  5. Status bar and toolbar positioning
    By SMurf in forum Windows Programming
    Replies: 3
    Last Post: 09-30-2001, 05:18 PM

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