Printing the text with color in 'C'

Home Forums Programming Printing the text with color in 'C'

Tagged: , ,

This topic contains 1 reply, has 2 voices, and was last updated by  Satish 5 years, 9 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #976

    Basavaraj
    Member
    #include<stdio.h>
    void main()
    {
    	int i;
    
    	for(i=0; i<15; i++ )
    	{
    	textcolor(i);
    	cprintf("Welcome to C\r\n");
    	}
    	getch();
    }
    

    In 'c' it is possible to print the text with color,when display text using printf() by default it will be displayed in white color,we could display text in different colors using cprintf() function.
    Before displaying the text using cprintf() we should define the color to be used using the function textcolor() it takes an integer argument ranging from 0 to 15 each number represents a unique color( it's list is given below).
    In order to display text with color we need to make use of two function's textcolor() and cprintf(). textcolor() defines the color to be used and cprintf() displays the text.

    Note: in order display text in nextline( new line ) it is required to use 2 escape sequences \r and \n together. \n alone will not feed new line in cprintf() as it would in printf().

    /*
    color color code
    —– ———–
    BLACK 0
    BLUE 1
    GREEN 2
    CYAN 3
    RED 4
    MAGENTA 5
    BROWN 6
    LIGHTGRAY 7
    DARKGRAY 8
    LIGHTBLUE 9
    LIGHTGREEN 10
    LIGHTCYAN 11
    LIGHTRED 12
    LIGHTMAGENTA 13
    YELLOW 14
    WHITE 15
    */

    #989

    Satish
    Keymaster
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.