I just moved to Linux for just a month. I’ve used Borland Turbo C for C programming but some of these functions do not work in GNU/Linux, so looking for help.
These are some of the functions I would like to replace:
– gotoxy
– cprintf
– clrscr
– initgraph/graphics.h
I would appreciate some code examples showing how to use any replacements.
In linux, you can use the ncurses library to use the terminal as a text buffer: move the cursor around, and write text. It can also draw windows and other hi-level widgets.
For
gotoxyseemoveandwmovefrom ncurses (link).For
cprintfseeprintw.You can clear the screen simply with
clear().In ncurses you also need to refresh the screen with
refresh()afterprintwandclear().Example program, which uses all the mentioned functions in ncurses:
Compile in gcc with:
gcc program.c -lcursesAs for graphics, you have to choose a particular library.
If you need a similar experience as the low-level graphics.h, you are probably looking for directfb or svgalib.
If you want to render graphics in a window, SDL will be helpful.