Changing Text Color In C/C++ Programming Language

Are you a newbie programmer learning C/C++ Programming Languages. Here is a new trick for you to make others and your classmates surprise. This trick will tell you, how you can change the Text Color, Blink a Text, or Change the Background Color.


textcolor function is used to change the color of drawing text in c programs.

Declaration :- void textcolor(int color);
where color is an integer variable. For example 0 means BLACK color, 1 means BLUE, 2 means GREEN and soon. You can also use write appropriate color instead of integer. For example you can write textcolor(YELLOW); to change text color to YELLOW. But use colors in capital letters only.

A List of Color codes can be found here : Color-Table

1. C programming code to change text color

#include<stdio.h>
#include<conio.h>
 
void main()
{
   textcolor(RED);
   cprintf("C programming");
 
   getch();
   
}

2. C programming code to BLINK the Text

#include<stdio.h>
#include<conio.h>
 
void main()
{
   textcolor(MAGENTA+BLINK);
   cprintf("C programming");
 
   getch();
   
}

Note that we have used cprintf function instead of printf. This is because cprintf send formatted output to text window on screen and printf sends it to stdin.
Share on Google Plus

0 comments: