Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clearing output of a terminal program Linux C/C++

Tags:

People also ask

How do I clear the screen in C program in Linux?

There are several methods to clear the console or output screen and one of them is clrscr() function. It clears the screen as function invokes. It is declared in “conio. h” header file.

How do I clear terminal output?

You can use Ctrl+L keyboard shortcut in Linux to clear the screen. It works in most terminal emulators.

How do I clear the command window C?

If you want to clear the console screen in C, you'll want to use system("clear") for Linux and macOS, or system("cls") for Windows.


I'm interested in clearing the output of a C program produced with printf statements, multiple lines long.

My initial guess was to use

 printf("output1\n");  printf("output2\n");  rewind(stdout);  printf("output3\n");  printf("output4\n"); 

but this produces

 output1  output2  output3  output4 

I was hoping it would produce

 output3  output4 

Does anyone know how to get the latter result?