5

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.

1
  • 2
    You need to specify your environment (Unix terminal/Windows console app/...) as this is beyond ISO C. Commented Dec 15, 2013 at 13:27

3 Answers 3

6

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; } 
Sign up to request clarification or add additional context in comments.

Comments

3

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

Comments

-5

No, you can't clear only a part of the console window.

2 Comments

You can't even clear the full screen in standard C++.
@BenjaminBannier Not part of the standard, but you can do system("cls") or system("clear") which works fine if refresh rate isn't too high.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.