For Windows console applications, in plain C:
#include <tchar.h>
#include <wincon.h>
VOID
ClearScreen(HANDLE hConsoleOutput)
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
COORD coPos;
DWORD dwWritten;
GetConsoleScreenBufferInfo(hConsoleOutput, &csbi);
coPos.X = 0;
coPos.Y = 0;
FillConsoleOutputAttribute(hConsoleOutput, csbi.wAttributes,
csbi.dwSize.X * csbi.dwSize.Y,
coPos, &dwWritten);
FillConsoleOutputCharacter(hConsoleOutput, TEXT(' '),
csbi.dwSize.X * csbi.dwSize.Y,
coPos, &dwWritten);
SetConsoleCursorPosition(hConsoleOutput, coPos);
}
...
// In your main code:
/* Clear the full console screen */
ClearScreen(hOutput);
where the `hConsoleOutput` is a HANDLE to a console screen-buffer (obtained either via `GetStdHandle(STD_OUTPUT_HANDLE)`, or `CreateConsoleScreenBuffer(...)`, or other means.
What this function does is to, first, retrieve the current console screen-buffer information (that contains its current size), then fill the complete screen-buffer with the default text attribute and with spaces, then finally place the cursor at (0,0).