1.0 CLEARING THE SCREEN: (Credit: robwhit)
OPTION 1
put this at the top of your source file:
#include <conio.h>
put this where you want the screen to clear:
clrscr();
Advantages:
Works fast. Simple.
Disadvantages:
Only DOS compilers have this function.
OPTION 2
putchar some newlines until everything is scrolled off of the screen.
Advantages:
It works.
Disadvantages:
The screen isn't always the same size, even in text modes, so there could be more lines than you think are there. (And its slow and hackish.)
OPTION 3
Use a text-mode library like curses or a port of it or something like that.
Advantages:
Portable, provided that you have the library
Disadvantages:
You have to get the library
OPTION 4
Write directly to video memory, clearing all the bits.
Advantages:
It works.
Disadvantages: Some OSs don't allow you to directly access hardware, finding out how to write to video memory can be a pain, don't expect it to be too portable...
OPTION 5
For all UNIX systems, using curses:
#include <curses.h>
void clrscr()
{
static int init;
if (init == 0)
{
initscr();
init = 1;
}
clear();
refresh();
}
OPTION 6
Throw the monitor out the window
Advantages:
Pretty fail-proof
Releases your anger
Disadvantages:
No more monitor.
If you forgot to unplug it, other computer peripherals might follow it in a racing frenzy
You have to open the window and take the screen out (the mesh thingie that keeps bugs out.... supposedly...)
(Note from webmaster: Not portable. Difficult to write code to throw monitor out window.)
WINDOWS OPTION: (Credit: Sunlight)
Just call the function clrscr(). Simple as that.
#include <windows.h>
void clrscr()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}