How to clear the console screen in C language?
In C language, there are several methods to clear the console content.
- clear the console
- clear the system display
#include <stdlib.h>
int main() {
// 清屏
system("cls"); // Windows系统
// system("clear"); // Linux系统
return 0;
}
- Clear the screen.
#include <stdio.h>
int main() {
// 清屏
printf("\033[2J");
return 0;
}
It should be noted that the method of using escape characters to clear the screen may not work on some consoles, so it is recommended to use system commands instead.