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!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.