ncurses
provides flexibility for the screen and input.
Link with -lncurses
#include <stdio.h>
#include <ncurses.h>
int main ( void) {
int ch = 0;
int row = 0;
int col = 0;
initscr ( );
halfdelay ( 2); // tenths of a second that getch waits for input
noecho ( );
getmaxyx ( stdscr, row, col); // max rows and cols
move ( row / 2, col / 2);
printw ( "hi");
refresh ( );
move ( row / 2, 2);
printw ( "hello");
refresh ( );
move ( row - 3, col / 4);
printw ( "press enter");
refresh ( );
while ( ( ch = getch ( ))) {
if ( '\n' == ch) {
break;
}
}
endwin ( );
return 0;
}
Escape codes are another possibility if your terminal supports them.
#include <stdio.h>
int main ( void) {
int row = 11;
int col = 20;
printf ( "\033[2J"); // clear screen
printf ( "\033[%d;%dH", row, col);
printf ( "hi");
fflush ( stdout);
printf ( "\033[%d;%dH", row, 2);
printf ( "hello");
fflush ( stdout);
printf ( "\033[%d;%dH", 18, 2);
fflush ( stdout);
return 0;
}