Help Please: Screen Location ( gotoxy? etc )

This is a discussion on Help Please: Screen Location ( gotoxy? etc ) within the C Programming forums, part of the General Programming Boards category; Well, Ive read the FAQ and done searches of this board and it appears that in theory I should be ...

  1. #1
    Registered User wavering's Avatar
    Join Date
    Dec 2001
    Posts
    26

    Question Help Please: Screen Location ( gotoxy? etc )

    Well, Ive read the FAQ and done searches of this board and it appears that in theory I should be able to jump to a precise location on the screen as follows:

    #include<conio.h>

    .....

    int i=30,j=50;
    gotoxy(i,j);

    Unfortunately this does not work on Microsoft QuickC 2.51. Is there another way? I appreciate that I can write direct into the video memory but have found that although this produces an .exe file which works on a machine running Windows 98 it does NOT work on a machine running Windows 2000 Professional. I assume that this is because it uses a totally different address for the screen ( actually I'm surprised it works with Win 98 )

    So any ideas? Many thanks.

    PS I have concluded that there are lots of different versions of .h files ... not really surprising, I suppose.

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    gotoxy is not ansi standard.
    use 2 loops 1 for lines 1 for columns
    Code:
    for(x = 0; x < line; x++)
        putchar('\n');
    for(x = 0; x < col; x++)
        putchar(' ');
    put that in your own function called gotoxy and you have it
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Registered User wavering's Avatar
    Join Date
    Dec 2001
    Posts
    26
    Thanks C_Coder but I am trying to write an ultra fast routine ( so anything looping is out ) which puts updates into various locations on the screen as things change.

    I need to jump instantly to the right place on the screen and not overright anything on the way or move anything either.

    Another alternative is to find a way to locate the start of screen address and just write into the video addresses ( a lot of the routine will be written in assembly language anyway ) This is a program which runs for several days (currently written in Quick Basic ) doing billions ( literally ) of iterations so even tiny delays are very significant.

    So - is the location of start of screen memory available anywhere as an address I can refer to? As opposed to just assumming it is at B800 as it usually is ..

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can use ANSI escape codes, assuming you're programming in DOS/console mode.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    from the FAQ....
    windows console version
    Code:
    #include <windows.h>
    void gotoxy(int x, int y)
    {
       COORD coord;
       coord.X = x;
       coord.Y = y;
       SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    If dos then look for ralf browns interrupt list to find out which interrupt call you have to make to achieve the same thing.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Registered User wavering's Avatar
    Join Date
    Dec 2001
    Posts
    26
    Thanks Stoned_Coder. Am using DOS based ( QuickC 2.51 ) system. Have only just looked at your post and have meanwhile solved problem as below:

    gotoxy(int x,int y) //Declare Function gotoxy
    {
    _asm
    {
    mov dl,x ;x coord
    mov dh,y ;y coord
    mov bh,0 ;page number ( search me ... )
    mov ah,2 ;Interrupt number 2
    int 10h ;Call BIOS
    }
    }

    main()
    {
    system("cls"); //Clear Screen
    gotoxy(40,10); //Move cursor
    putchar('X'); //Put "X" on screen
    }

    I find inline asm a lot easier than finding obscure C functions and you are more or less at the coal face...

    As for Ralf Brown's list had not heard of it but I assume this is it:

    http://www.ctyme.com/rbrown.htm

    and you will see the cursor stuff here:

    http://www.ctyme.com/intr/rb-0087.htm

    As for it being in FAQ you are quite right it is in "various". I had looked but had not spotted it ... obviously it would be under various rather than under cursor - silly me. Here:

    http://www.cprogramming.com/boardfaq.html#various

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Render text
    By Livijn in forum C++ Programming
    Replies: 6
    Last Post: 07-06-2007, 03:32 PM
  2. Feedback: Functional Specification Wording
    By Ragsdale85 in forum C++ Programming
    Replies: 0
    Last Post: 01-18-2006, 03:56 PM
  3. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 09:18 PM
  4. i am not able to figure ot the starting point of this
    By youngashish in forum C++ Programming
    Replies: 7
    Last Post: 10-07-2004, 02:41 AM
  5. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM

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