Reputation:
I want to clear the output of my program in C (on terminal/console). I see that most website just use system("cls")
(Windows) or system("clear")
(Linux), but it's not standard and also platform dependant. How can I accomplish that with standard C?
Upvotes: 2
Views: 181
Reputation: 773
See description of the ANSI clear screen commands here
There are a lot of different ways to use ANSI characters.
#include <stdio.h>
int main()
{
printf("\033[2J");
return 0;
}
Another answer Clearing the screen by printing a character?. Covers a variety of other ANSI codes, see examples there.
How to judge whether stdout supports ANSI escape code is an answer that discusses the ANSI supported terminal in the year 2021 and a method for testing for ANSI support.
Upvotes: 3