gotoxy in dev c++

F

furqan shaikh

sir how can we use gotoxy() in dev c++ as we do in TC++ . if it is not
present then what is the way to make our own.

by using the combination of ascii codes. to move througout the screen.
 
R

red floyd

furqan said:
sir how can we use gotoxy() in dev c++ as we do in TC++ . if it is not
present then what is the way to make our own.

by using the combination of ascii codes. to move througout the screen.

Wrong group. gotoxy() is not standard C++.
 
J

Jorgen Grahn

This is offtopic, but ncurses isn't portable to Windows, which furquan
apparently uses.
In addition, if the ultimate goal is to draw a 2D graph, using GnuPlot is

It seems unlikely that he wants to draw graphs; there's nothing about
in the question which suggests that is what he wants to do.

/Jorgen
 
J

James Kanze

In addition, if the ultimate goal is to draw a 2D graph, using
GnuPlot is a better option... there are even some C++ classes
freely available on the net to interface it to your code.

I'm not sure what gotoxy() did in TC++, but if it is anything
like the gotoxy() in curses (and "using the combination of ASCII
codes to move throughout the screen" certainly suggests that it
is something similar), then it's not used to draw 2D graphs, but
to position the cursor on the screen. This sort of thing used
to be frequently used to generate masks for input and such. (In
modern code, one would normally use a GUI. But there's still a
lot of mask based code around that needs to be maintained.)
 
J

James Kanze

This is offtopic, but ncurses isn't portable to Windows, which
furquan apparently uses.

ncurses is an implementation of the Open Group curses standard
(http://www.opengroup.org/onlinepubs/007908799/cursesix.html).
I don't know about ncurses, precisely, but there definitely have
been ports of some implementations of this standard to MS-DOS.
(I've used them.) And since it normally operates in a console
window, presumably, some of the DOS ports will probably work
under Windows as well. (Some of them probably used direct
access to the screen backing memory, which of course won't work
under Windows. But at least one of them required installing the
ANSI driver, obviously so that it wouldn't need direct screen
access.)

I'm too lazy (or not interested enough---yeh, that sounds
better) to do it now, but there is a port of nethack to windows,
and nethack uses the basic curses, so you might want to see what
they use or how they do it.
 
J

James Kanze

Wrong group.  gotoxy() is not standard C++.

But it's portable C++. For what it does, it could probably be
considered a defacto standard. (Strictly speaking, it's
standard, and it's C++. It's just that the standard in question
isn't the C++ standard:).)
 
D

dickey

ncurses is an implementation of the Open Group curses standard
(http://www.opengroup.org/onlinepubs/007908799/cursesix.html).
I don't know about ncurses, precisely, but there definitely have
been ports of some implementations of this standard to MS-DOS.
(I've used them.)  And since it normally operates in a console

PDCurses is the best-known implementation for MS-DOS (though there
probably have been some others, it's been quite a while since I've
seen even the non-working fragments of alternatives ;-).

In principle, one could port ncurses to Windows, but so far there's
been enough work to do...
 
K

Krice

if it is not present then what is the way to make our own.

Back a while I ported some old project and there was no gotoxy
and some others so I made quick and dirty ones with Windows.
Note that I used get_key() to replace getch() which doesn't
seem to work in Windows console. This source is highly
non-portable:)

#include <windows.h>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <conio.h>
#include <sys\stat.h>

HANDLE wHnd; //Handle to write to the console
HANDLE rHnd; //Handle to read from the console

void get_window_handles()
{
//Set up the handles for reading/writing, call
//this once before using routines
wHnd=GetStdHandle(STD_OUTPUT_HANDLE);
rHnd=GetStdHandle(STD_INPUT_HANDLE);
}

void clrscr() { system("CLS"); }

void gotoxy(short x, short y)
{
COORD c;
c.X=x; c.Y=y;

SetConsoleCursorPosition(wHnd,c);
}

void textattr(unsigned char c)
{
int textColor=c & 0x0f;
int backGroundColor=(c & 0xf0)>>4;
SetConsoleTextAttribute(wHnd,
(WORD)((backGroundColor << 4) | textColor));
}

short get_key()
{
INPUT_RECORD rec;
DWORD num;

do { ReadConsoleInput(rHnd, &rec, 1, &num); }
while (num==0 || rec.EventType!=KEY_EVENT ||
rec.Event.KeyEvent.bKeyDown==FALSE);

short rv=rec.Event.KeyEvent.uChar.AsciiChar;

//if no ascii code detected, return virtual key code (VK_*)
if (rv==0) rv=rec.Event.KeyEvent.wVirtualKeyCode;

return rv;
}
 
J

James Kanze

PDCurses is the best-known implementation for MS-DOS (though
there probably have been some others, it's been quite a while
since I've seen even the non-working fragments of alternatives
;-).
In principle, one could port ncurses to Windows, but so far
there's been enough work to do...

And probably not that much interest. Presumably, it would only
be used for porting legacy software from Unix; anything new
would just use windows.

Still, does anyone know what nethack uses? It has an "#include
<curses.h>" in its windows specific code. (The other program I
know of which uses full screen character based display in a
Windows console window is vim, but it seems to use termcap
directly under Unix.
 
D

dickey

Still, does anyone know what nethack uses?  It has an "#include
<curses.h>" in its windows specific code.  (The other program I

It uses termcap (look for tgetent).
 
Joined
Dec 30, 2009
Messages
1
Reaction score
0
Back when i was in school (they used windows, i use GNU/Linux), i used conio.h for DOS/Win32 support of the basic functions of curses.h, and simply added a lot of "#ifdef"s to switch between conio.h and curses.h code.
See conio.sourceforge.net
P.S. If you use a Borland or M$ compiler, conio.h should already be present (it's probably in Watcom too, not sure), and there is a package for Bloodshed Dev-C++ available from the package manager.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top