Equivalent to conio.c?
Hi, I need to compile using GCC 3.3 some code that was written with VisualStudio and which is dependent on conio.C (specifically the gotoxy function), library which AFAIK is not available for OS X.
Does anyone know of a workaround for that? Maybe a function which would work in a similar way to conio.c's gotoxy?
TIA,
Kinniken
[358 byte] By [
Kinniken] at [2007-11-18 19:13:49]

# 1 Re: Equivalent to conio.c?
There is no gotoxy in VC's conio.h , but as far as I remember there is one in Borland C(++). But hum, sorry I don't know what you could use in GCC to simulate that.
# 3 Re: Equivalent to conio.c?
Use the curses library. You'll need to call initscr() at the beginning of your app and call endwin() at the end of your app. The gotoxy() function will be replaced by curses' move() function. You'll need to call refresh() after every call to move(). Here's some sample code:
/* curses_test.c */
#include <stdio.h>
#include <curses.h>
void die()
{
/* ignore interrupts */
signal(SIGINT, SIG_IGN);
/* move cursor to lower left */
mvcur(0, COLS - 1, LINES - 1, 0);
/* make terminal the way it was */
endwin();
exit(0); /* exit normally */
}
/* combine move() and refresh() into a single call */
int movexy(int x /*column */, int y /* line */)
{
int result = move(y, x);
if (result == 0)
{
result = refresh();
}
return result;
}
int main()
{
/* init stdscr, curscr and terminal for use by curses library */
initscr();
/* call die() if get interrupt */
signal(SIGINT, die);
movexy(1,1);
/* Notice how both \n and \r need to be specified */
printf("Hi there!\n");
printf("Hello again.\r\n");
printf("Goodbye!\r\n");
/* pause for 5 seconds */
sleep(5);
/* end program */
die();
/* Never get here -- but include to avoid compiler error */
return 0;
}
You must link to the curses library too:
gcc curses_test.c -o curses_test -lcurses
Three things you must note using curses is:
* "\n" only moves down a line. It does not cause the cursor to move back to the beginning of line. You'll need "\r" for that.
* You cannot redirect output when using curses
* You must call endwin() at the end of your program or your terminal session will be screwed up. That is why the example program sets up die() to be called on the SIGINT signal.
Hope that helps!
- Kevin