-2

Turbo C offered gotoxy() function in conio.h but it was not a standard.

I use gcc compiler and need gotoxy() function.

I searched online but found only functions which are specific to OS or have some kind of dependency which makes it less portable.

eg: gotoxy() function for windows use the Windows API and for linux it uses things like ncurses.

I found a suggestion in here

which mentions something about setting up a 2-d array, assigning values to cells and plotting.

Screenshot

When I attempted it, one of the problems was that after a new line has been printed there's no going back without a gotoxy() function.

Any help would be appreciated.

Community
  • 1
  • 1
J...S
  • 5,079
  • 1
  • 20
  • 35
  • 2
    *...found only functions which are specific to OS or have some kind of dependency which makes it less portable.* Yes, that is correct. – user3386109 Sep 16 '16 at 20:46
  • 2
    You don't want a dependency? But what do you think depending on `` or TurboC is? For POSIX platforms, if you want advanced textual interfaces then using ncurses *is* the "standard" solution. And it exists Windows ncurses libraries, both emulated in Cygwin/MinGW&MSYS and "native" Windows. – Some programmer dude Sep 16 '16 at 20:46
  • 1
    @JoachimPileborg: There's also `pdcurses` on Windows. – Tim Čas Sep 16 '16 at 20:51
  • @JoachimPileborg What I meant was that I want the programs using this function to run on both windows and linux. I need it to be portable. – J...S Sep 16 '16 at 20:52
  • Then you have two possibilities: Either use some library that exists on all platforms you want to build on (like the curses variants); Or code it up all yourself. I know which solution I would choose. – Some programmer dude Sep 16 '16 at 20:55
  • Can someone tell me how to code a gotoxy() function by setting up a 2-d array, assigning values to cells and plotting ? – J...S Sep 16 '16 at 20:58
  • @J...S There is no way to write such a function portably. The C language does not standardize the facilities needed to implement such a function. You *must* depend on platform-specific features or use a third-party library (such as ncurses) that abstracts away platform differences (thereby allowing *your* code to be portable). – jamesdlin Sep 16 '16 at 21:42
  • http://www.c-faq.com/osdep/termcap.html – jamesdlin Sep 16 '16 at 21:44
  • Do you think existing solution have OS dependencies just to annoy you? – n. m. could be an AI Mar 19 '18 at 18:23

1 Answers1

1

You will always necessarily have dependencies because the nature of console I/O is platform specific. The purpose of a library such as ncurses is to abstract such platform dependencies to provide a common interface.

ncurses is available for a wide range of platforms including Windows,

Clifford
  • 88,407
  • 13
  • 85
  • 165