Open In App

Print colored message with different fonts and sizes in C

Last Updated : 13 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In C/C++ we can use graphics.h header file for creation of programs which uses graphical functions like creating different objects, setting the color of text, printing messages in different fonts and size, changing the background of our output console and much more.
Here we will create a program which will print message (“geeks”) in colored form in different font style and size. listed below are some function used :

  • setcolor(): It will set the cursor color and hence anything written on the output screen will be of the color as per setcolor().
    function prototype :

    setcolor(int)
  • settexttyle(): It set the text font style, its orientation(horizontal/ vertical) and size of font.
    Function prototype :

    settextstyle(int style, int orientation, int size);
  • outtextxy() : It will print message passed to it at some certain coordinate (x,y).
    function prototype :

    settextstyle(int style, int orientation, int size);
  • More functions:
    TextHeight():

    textheight();

    TextWidth():

    textwidth();

    SetUserCharSize():-

    setusercharsize(x1,y1,x2,y2);

Note: Given program will not run on IDE, try it on your compiler




// C program to print
// message as colored characters
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
  
// function for printing
// message as colored character
void printMsg()
{
    // auto detection
    int gdriver = DETECT,gmode,i;
  
    // initialize graphics mode
    initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");
  
    for (i=3; i<7; i++)
    {
        // setcolor of cursor
        setcolor(i);
          
        // set text style as
        // settextstyle(font, orientation, size)
        settextstyle(i,0,i);
          
        // print text at coordinate x,y;
        outtextxy(100,20*i,"Geeks");
          
        delay(500);
    
    delay(2000);
}
  
// driver program
int main()
{
    printMsg();
    return 0;
}


Output:

color


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads