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

Adding color Text in C
Adding color Text in C

Opaque Text Color In C

 

END

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.

thesmolt App

 

Leave a Reply

x