Adding color Text in C
In this article, we learn how to Display color font in the C programming language, without using getcolor() Function, Adding color Text in C like Opaque Text Color.
Text Color In C
#include<stdio.h>
// back ground colours
#define bgBlack β\e[40mβ
#define bgRed β\e[41mβ
#define bgGreen β\e[42mβ
#define bgYellow β\e[43mβ
#define bgBlue β\e[44mβ
#define bgMagenta β\e[45mβ
#define bgCyan β\e[46mβ
#define bgWhite β\e[47mβ//bright background colours
#define bgbBlack β\e[40;1mβ
#define bgbRed β\e[41;1mβ
#define bgbGreen β\e[42;1mβ
#define bgbYellow β\e[43;1mβ
#define bgbBlue β\e[44;1mβ
#define bgbMagenta β\e[45;1mβ
#define bgbCyan β\e[46;1mβ
#define bgbWhite β\e[47;1mβ// foreground light colours
#define fgBlack β\e[30mβ
#define fgRed β\e[31mβ
#define fgGreen β\e[32mβ
#define fgYellow β\e[33mβ
#define fgBlue β\e[34mβ
#define fgMagenta β\e[35mβ
#define fgCyan β\e[36mβ
#define fgWhite β\e[37mβ//foreground bright colors
#define fgbBlack β\e[30;1mβ
#define fgbRed β\e[31;1mβ
#define fgbGreen β\e[32;1mβ
#define fgbYellow β\e[33;1mβ
#define fgbBlue β\e[34;1mβ
#define fgbMagenta β\e[35;1mβ
#define fgbCyan β\e[36;1mβ
#define fgbWhite β\e[37;1mβ//reset foreground and background to normal colours
#define Reset β\e[0mβ
void txtColor(char a[]);
void bgColor( char b[]);
int main()
{txtColor(fgBlue);
printf(β\nThis is Blue Color β);
txtColor(Reset);txtColor(fgGreen);
printf(β This is Green Color \nβ);
txtColor(Reset);txtColor(fgRed);
bgColor(bgWhite);printf(βThis is Red Color text, Under White Colorβ);
txtColor(Reset);return 0;
}void txtColor(char a[]){
printf(β%sβ,a);
}
void bgColor(char b[]){printf(β%sβ,b);
}
Get color in C program
Opaque Text Color In C
C program to draw a square using graphics (clickHere)
Color Font and Background in C
Note:- Maybe sometime above code doesnβt get user-friendly output, in codeblock βorβ any other EDITOR, All of C & C++ program tested in DOS compiler Turbo C.
Also Read
Types of functions in CΒ Β Read Here
I hope you will understand better if you study at M.U, in the exam of M.U you know how important this βAdding color Text in C
β . So please donβt forget to give your valuable feedback. Go in the comment section and Give us some feedback about it. Adding color Text in CΒ or My website.
Our team check your every Comment per day Because your one feedback helps us in growing Thesmolt
I request you if you have any doubt or question regarding our site, then please donβt hesitate. We always waiting for your Suggestion.
Note:- If you want to Download This articleβs in PDF form, then simply go (Top or Bottom of) Right corner and click on the PRINT icon, and itβs saved as a PDF ofΒ Adding color Text in C
For further questions, you can contact us Via mail [email protected]Β otherwise, Our Help Page and Contact us Page, which is included below. I hope Iβll able to say all the possible ways to reach us. Or Download My Android Application Below Download Button.