Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » gotoxy

This thread is locked; no one can reply to it. rss feed Print
gotoxy
xerophreak
Member #745
November 2000

I'm having some trouble with the gotoxy function. whenever i tell it to go to xy and cout anything, it just couts what i tell it to where the rest of the output ended...it doesn't move anywhere...i'm using the function...
void gotoxy(int x, int y);
and then telling it
cout<<"hello";
and all i get is hello right where the rest of my output left off...please help
Xero

Bruce Perry
Member #270
April 2000

Remember the top left corner of the screen is (1,1), not (0,0). I suspect it would ignore a call with one of the coordinates 0.

If this doesn't work, try using printf() or cprintf() instead of cout - although I'd have thought it should work.

Ben Davis

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

xerophreak
Member #745
November 2000

I'm trying to give it the coordinates (15,15)but it just doens't do anything

George Foot
Member #669
September 2000

The conio system works by writing directly to video memory. stdout (used by printf and cout) is a file descriptor. You can't mix the two. So, if you want to use gotoxy you have to use the other conio routines too, and no stdio routines or others that use stdout. That is, use cprintf or cputs. Maybe somebody has made a streamed version of it too, but I think it's more likely that someone has made a stream wrapper for gotoxy as well.
George

xerophreak
Member #745
November 2000

the compiler we started on would work with the gotoxy function, but this one won't. i just need it to go frmo point to point and place a random character. any ideas on what i could get to do that?

gswork
Member #771
November 2000

xero,

Use conio.h as gfoot advised, for the random trickery you could fill an array with the characters you want and then point randomly to them.

So in C you could 'char' an array of characters then declare a pointer to use in randomly (get a random Nr) pointing at an element in the array.

You could set up the random selecting as a little function to return the character and call it inside a loop in main() or elsewhere however many times you want.

I'm sure there are various other ways too, like stopping the same character from appearing twice etc.

xerophreak
Member #745
November 2000

can someone give me an example of how to do it???

parasync
Member #683
October 2000

cprintf, same as printf only it works with textcolor(int), textbackground(int) and gotoxy(int, int)

xerophreak
Member #745
November 2000

that's great and all, but can someone give me an example program that will print out an "X" at (15,15) ??

Thomas Harte
Member #33
April 2000
avatar

#include <conio.h>
int main(void)
{
gotoxy(15,15);
cprintf("X");
return 0;
}

Thomas Harte
Member #33
April 2000
avatar

Your previous C compiler was probably developed entirely with DOS in mind, so has a 'thrown together' stdout/stderr/stdin, hence it working where DJGPP does not. Be warned though : conio.h and gotoxy are very DOS things to do still, don't expect to be able to port even to Linux console if you're doing that kind of thing. I think 'curses' is the cleanest (for portability) thing to use for text mode manipulation . . .

xerophreak
Member #745
November 2000

it says ...
c:\mydocu~1\kevin.cpp:4: implicit declaration of function `int gotoxy(...)'
c:\mydocu~1\kevin.cpp:5: implicit declaration of function `int cprintf(...)'

parasync
Member #683
October 2000

Save all your data into an array of chars..
like:
char screen_array[94][34];
and print it to the screen everytime you write something..
use putc to write to array

Bruce Perry
Member #270
April 2000

To solve 'implicit declaration' warnings, make sure you include the appropriate header files. I think you need conio.h - check the docs.

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Go to: