Print text in different fonts using graphics.h in C

In this article, we are going to learn about the settextstyle() and outtextxy() function of graphics.h header file and use them to print message on console in different style of fonts.
Submitted by Manu Jemini, on March 21, 2018

This is very useful if we can change the way our text appears. The Fonts, Size and the directions are the crucial part of the styling of the texts.

There is a very useful function called settextstyle() which takes three parameters which define font, direction, charsize of the text. These are all numbers therefore in the example below, you can see the for loop which is providing the input for the function.

You can also pass the exact number for the font or charsize or direction of the text. This is a fairly useful concept because all you need is a number to be passed to the function before outputting the text on the screen.

graphics.h - Print text in different fonts in C

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

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

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

	//Printing message for user
	outtextxy(20, 20 + 20, "Program to print different fonts in C graphics");

	//initilizing variables
	int x = 75, y = 75, f = 0;

	//for loop to print different fonts
	for (f = 0; f <= 5; f++)
	{
		settextstyle(f, HORIZ_DIR, 1);
		outtextxy(x, y, "Testing different fonts..");
		y = y + 20;
	}

	getch();

	return 0;
}

Output

graphics.h - Print text in different fonts using graphics.h in C



Comments and Discussions!

Load comments ↻





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