Reputation: 701
Is it possible to clear multiple lines in C and keep others for example.
Code:
Displaysenrsordata
loop
printf("This info stays"); <-stay on screen
printf("This info stays"); <-stay on screen
printf("This info Refreshes"); <-update redraw
printf("This info Refreshes"); <-update redraw
printf("This info Refreshes"); <-update redraw
Essentially I want to have some text to stay at the same place and redraw the updating data without clearing the whole screen.
Upvotes: 5
Views: 2389
Reputation: 2853
If you are working on linux then use ncurses.
Example:
#include <stdio.h>
#include <ncurses.h>
int main (void)
{
int a = 0;
initscr ();
printw("This info stays \n");
printw("This info stays\n");
curs_set (0);
while (a < 100) {
mvprintw (3, 4, "%d", a++);
mvprintw (3, 8, "%d", a++);
mvprintw (3, 12, "%d", a++);
refresh ();
sleep (1);
}
endwin();
return 0;
}
Upvotes: 6
Reputation: 70951
You can overwrite the current line be printing out a \r
, or the last character on the current line by printing a \b
.
Upvotes: 3