How do I Clear the screen? | |
The best method to clear the screen may be for you to review your compilers documentation and find a suitable non-standard function (such as clrscr from conio.h). The following options will give you the results you desire as quick fixes. Here are some options that may be open to you. OPTION 1 Write newline characters until everything has scrolled off of the screen: #include <stdio.h>
#define SCREEN_HEIGHT 25
int main ( void )
{
int i;
for ( i = 0; i < SCREEN_HEIGHT; i++ )
putchar ( '\n' );
return 0;
}
Advantages:
Disadvantages:
Use a text-mode library that supports the feature you want. Advantages:
Disadvantages:
Write directly to video memory, clearing all the bits. Advantages:
Disadvantages:
Throw the monitor out the window Advantages:
Disadvantages:
Use the system function to call your OS's command line screen clearing program. This simulates what the user would do if you weren't so interested in clearing the screen. #include <stdlib.h>
int main ( void )
{
system ( "cls" ); /* Or system ( "clear" ); for POSIX */
return 0;
}
Advantages:
Disadvantages:
Define your own function using a platform-dependent method. For example, here is a function to clear the screen in Windows: #include <windows.h>
void clear_screen ( void )
{
DWORD n; /* Number of characters written */
DWORD size; /* number of visible characters */
COORD coord = {0}; /* Top left screen position */
CONSOLE_SCREEN_BUFFER_INFO csbi;
/* Get a handle to the console */
HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
GetConsoleScreenBufferInfo ( h, &csbi );
/* Find the number of characters to overwrite */
size = csbi.dwSize.X * csbi.dwSize.Y;
/* Overwrite the screen buffer with whitespace */
FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
GetConsoleScreenBufferInfo ( h, &csbi );
FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );
/* Reset the cursor to the top left position */
SetConsoleCursorPosition ( h, coord );
}
|
Home
Application Tips
C++ screen clearing methods
Clear screen C programming
Console screen clear
How to clear screen C
Portable screen clearing
Programming Language
Screen clearing options
Turbo C
Clear the Screen in C++ Programming: A Quick Guide
Clear the Screen in C++ Programming: A Quick Guide
Tags
# Application Tips
# C++ screen clearing methods
# Clear screen C programming
# Console screen clear
# How to clear screen C
# Portable screen clearing
# Programming Language
# Screen clearing options
# Turbo C
About Sumit Kanadiya
We provides useful digital tips and resources on software, apps and gadgets you can’t live without. Our aim is to become your favorite digital resources destination on the web.
Turbo C
Labels:
Application Tips,
C++ screen clearing methods,
Clear screen C programming,
Console screen clear,
How to clear screen C,
Portable screen clearing,
Programming Language,
Screen clearing options,
Turbo C
