user19102267
user19102267

Reputation:

Standard method to clear the output in C?

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

Answers (1)

atl
atl

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

Related Questions