Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear multiple lines

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.

like image 930
user1031204 Avatar asked Oct 02 '22 03:10

user1031204


2 Answers

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;
 }
like image 114
sujin Avatar answered Oct 13 '22 09:10

sujin


You can overwrite the current line be printing out a \r, or the last character on the current line by printing a \b.

like image 38
alk Avatar answered Oct 13 '22 10:10

alk