Home » C programs » graphics.h header file functions

cleardevice() function of graphics.h in C

In this article, we are going to learn about the use of cleardevice() function of graphics.h header file in C programming language and try to clear the device screen using it after printing the message for user.
Submitted by Manu Jemini, on March 24, 2018

Clearing the screen is always an issue for developers, because now and then we want to show the user some useful or important data, which should be highlighted or at least have user’s attention.

To clear the console window or we can say the graph itself, just call the function cleardevice() and it will clear the screen.

It is important to note that, after clearing the device, we will lose all our drawing, shapes or images. It is useful but be little cautious.

graphics.h - cleardevice() function in C



#include <graphics.h>
#include <conio.h>

int main() 
{
	//initilizing graphic driver and 
	//graphic mode variable
	int graphicdriver=DETECT,graphicmode;

	//calling initgraph
	initgraph(&graphicdriver,&graphicmode,"c:\\turboc3\\bgi");

	//Printing message for user
	outtextxy(20, 20 + 20, "Program to use graph default in C graphics");

	//message to clear screen
	outtextxy(20, 50 + 30, "Press any key to clear screen");

	//getting character and clear the device screen
	getch();
	cleardevice();

	//message to press key to get exit from program
	outtextxy(20, 20 + 20, "Press any key to exit...");

	getch();
	
	return 0;
}

Output

cleardevice() function of graphics.h in C 1
cleardevice() function of graphics.h in C 2





Comments and Discussions




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.