Home › Forums › Programming › Printing the text with color in 'C'
- This topic has 1 reply, 2 voices, and was last updated 12 years, 10 months ago by Satish.
- AuthorPosts
- January 5, 2012 at 2:54 am#976BasavarajMember
#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
*/January 5, 2012 at 2:37 pm#989SatishKeymaster - AuthorPosts
- You must be logged in to reply to this topic.