Change Text Color in C
To change the text color in C you need to install my ‘.c’ file using the link below :
After downloading the file copy it and paste it in C > MinGW > include
Then you need to include my file like this ‘#include <Change_Colour.c>‘
The basic code will be :
#include <stdio.h> #include <Change_Colour.c> int main() { return 0; }
Simple Functions
Now to change color the functions are as follows :
Black | change_colour_to_black(); |
Red | change_colour_to_red(); |
Green | change_colour_to_green(); |
Yellow | change_colour_to_yellow(); |
Blue | change_colour_to_blue(); |
Purple | change_colour_to_purple(); |
Cyan | change_colour_to_cyan(); |
White | change_colour_to_white(); |
By using these functions you can change the color of the output text.
Advanced Functions
There is one advanced function in this file : change_colour(color_val, bold);
The color can be changed by the value of the parameter ‘color_val’.
The following table shows describes it :
0 | Black |
1 | Red |
2 | Green |
3 | Yellow |
4 | Blue |
5 | Purple |
6 | Cyan |
7 | White |
Now for the second parameter ‘bold’ there can be 2 values ‘1’ or ‘0’ as describes in the following table:
0 | Un Bold |
1 | Bold |
The code can be like this as follows :
#include <stdio.h> #include <Change_Colour.c> int main() { printf("\n"); change_colour_to_black(); printf("black \n"); change_colour_to_blue(); printf("blue\n"); change_colour_to_cyan(); printf("cyan\n"); change_colour_to_green(); printf("green\n"); change_colour_to_purple(); printf("purple\n"); change_colour_to_red(); printf("red\n"); change_colour_to_white(); printf("white\n"); change_colour_to_yellow(); printf("yellow\n"); change_colour(7, 0); printf("Text unbold\n"); change_colour(7, 1); printf("Text bold\n"); printf("\n"); return 0; }
Output :