Skip to content
Related Articles

Related Articles

Print colored message with different fonts and sizes in C
  • Difficulty Level : Easy
  • Last Updated : 29 Oct, 2018

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

This article is contributed by Shivam Pradhan (anuj_charm). If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :