How to use clrscr() in NetBeans
This is specially for NetBeans users. Sometimes you might be facing some problems when you have to use "clrscr()" in C/C++ in NetBeans.
The reason is the NetBeans IDE does not supports conio.h header file and "clrscr()" is included in that library.
So this is the how you can use clrscr() alternate and clear the screen.
Step 1:
include windows.h header file
#include<windows.h>
Step 2:
Create the function mentioned below.
void clear_screen()
{
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 );
}






0 comments:
Post a Comment