Clear screen in C and C++ on UNIX-based system?

user2355660 picture user2355660 · Jun 24, 2013 · Viewed 70.2k times · Source

I want to know: how to clean screen on an UNIX-based system? I searched on the Internet, but I've just found how to do it on Windows: system("CLS") I don't want exactly to clean cpmpletely the screen, but I want to open a "new page", such as in the NANO and VI editors. Thanks

Answer

David Ranieri picture David Ranieri · Jun 24, 2013

Maybe you can make use of escape codes

#include <stdio.h>

#define clear() printf("\033[H\033[J")

int main(void)
{
    clear();
    return 0;
}

But keep in mind that this method is not compatible with all terminals