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.
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;
}
You can overwrite the current line be printing out a \r
, or the last character on the current line by printing a \b
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With