# gotoxy substitute in os x?



## SAbsar (Nov 21, 2003)

Im using my mac to practice with the C they teach us in college. I have had to use workarounds from DOS such as system("clear"); on the mac instead of clrscr(); in dos, plus getchar(); instead of getch();

Anways, theres this function that i havent been able to find a workaround to... the gotoxy(x,y); function... can anyone tell me what is the UNIX/OSX equivalent of gotoxy??


----------



## donkey (Nov 21, 2003)

that sounds like a user-defined function.  at the very least, it isn't descriptive.  can you tell us what it is supposed to do, what types x and y are, maybe post some code?


----------



## SAbsar (Nov 21, 2003)

Okay, so this is how it goes - gotoxy(x,y) functions gets the cursor to the x,y coordinates on the screen, wthout erasing anything on the screen. I could have done this with a loop and printing spaces, but that would erase stuff on the way!
It is a part of the Borland C compiler, but isnt available on the mac


----------



## donkey (Nov 21, 2003)

sounds like you might be in trouble.  i have no ideas other than for you to write your own function.  you say that you can but it deletes everything in its path?  why not get whatever character is in the location and store it so  you can replace it as you go?  maybe someone else has better ideas, but thats all i can tell you.


----------



## wadesworld (Nov 22, 2003)

To do this in Unix (i.e. OS X), you'll need to use the ncurses library.

You initialize the library and then use the move() function to move the cursor.  So, for your project, you'll want to write your own implementation of gotoxy() that calls move().

See the ncurses man page for complete details.

Wade


----------



## SAbsar (Nov 23, 2003)

Hey wadesworld, i tried using the ncurses library and the move function with the refresh function... but project builders giving me lots of errors ! i havent been able to get the job done yet!


----------



## kainjow (Nov 24, 2003)

gotoxy() is part of Borland's conio.h which is I think only available through them. So yea you have to use that curses.h thingy or whatever for OS X (not sure exactly).


----------



## wadesworld (Nov 24, 2003)

sabsar,

I'll see if I can put together a quick example later tonight.

Wade


----------



## wadesworld (Nov 25, 2003)

Sabsar,

Check out:

http://homepage.mac.com/wadesworld/FileSharing8.html

There you'll find an example project builder project.  Note that I used Project Builder from Panther, so if it won't open under an earlier OS - just copy the main.cpp file into a new project and add /usr/lib/ncurses.dylib to the project.

Also, pay attention to the note in the comments - if you're on Panther, you'll have to change the terminal type to vt100 for the program to work, since ncurses doesn't like the default xterm-color type.  I'm sure there's a way to fix that, but I didn't take time to figure it out.

Hope this helps.

Wade


----------



## SAbsar (Nov 26, 2003)

Thanks wades, but it seems like i will just HAVE to use the PC for college stuff, coz they are moving us to graphics, and from what i hear, UNIX has nothing to do with graphics...  Damn i feel bad returning to the PC world!


----------



## kainjow (Nov 26, 2003)

SAbsar said:
			
		

> Thanks wades, but it seems like i will just HAVE to use the PC for college stuff, coz they are moving us to graphics, and from what i hear, UNIX has nothing to do with graphics...  Damn i feel bad returning to the PC world!


I feel ya bro  - I'm doing C++ and originally thought I could use my Mac but nope gotta use the crap Winblows machines


----------



## wadesworld (Nov 26, 2003)

Sabsar,

What kind of graphics?  If they're that DOS oriented, there's a good chance they don't know what exists on Unix.

Most colleges teach concepts that are platform-independent.  I'm very surprised they'd teach something like DOS graphics.

Now if they're teaching something modern, like OpenGL, you can easily do that on the Mac.

Wade


----------



## SAbsar (Nov 27, 2003)

Be prepared for surprises  they ARE teaching us dos graphics  they say its gonna give us the *hang* of the stuff... yeah right!


----------



## rhg (Nov 28, 2003)

I admit, programming DOS graphics gives you an insight into the inner workings of a graphics processor, e.g. how video memory is organized etc..

In today's world with Java frameworks and high level graphics abstractions like OpenGL it seems that this kind of knowledge does not matter anymore. However, my experience is the opposite. Personally, I benefit a lot from knowing the inner workings at hardware level (I started with quite primitive 8bit processors in the early 80s, we had to implement every detail down to the hardware level e.g. doing i/o with the floppy controller and funny stuff like that).

Unfortunately, you cannot do this cross-platform, so for your current studies you are bound to the DOS platform.


----------



## jarinteractive (Nov 30, 2003)

I used ncurses in place of gotoxy for one of my C++ courses a couple years ago.  It worked really well, but I had to run it in the terminal instead of in ProjectBuilder/xCode.

-JARinteractive


----------



## SAbsar (Nov 30, 2003)

Oh yes? can you please tell me how? i,too, use the terminal to run my programs. Things just dontwork out at the compiler!


----------



## jarinteractive (Nov 30, 2003)

Well, I went back and tried to compile my old program and it doesn't want to compile anymore (I created it back on OS X 10.1)!  I actually used curses.h instead of ncurses, also.  I did notice that you need to compile using the -lncurses option.  I remember that I found a good curses tutorial by searching Google, too.  Hope that helps a little...If you still need help I'll try to dig up something that actually works 

-JARinteractive


----------



## wadesworld (Dec 2, 2003)

> I actually used curses.h



Correct.



> you need to compile using the -lncurses option



Correct - if you don't include the library, it won't work.

There should be no problem compiling at the command line.  Take the sample project I posted, pull out the main.cpp file and throw everything else away.  You should be able to compile that at the command line without difficulty.

If you can't, post the errors.

Wade


----------

