Hello Programmers,
In this post you will learn about changing the Color of Text on Console using Code::Blocks IDE and MinGW Compiler.
Color Codes:
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White
*/
In this post you will learn about changing the Color of Text on Console using Code::Blocks IDE and MinGW Compiler.
Here we are using a function sytem() which is defined in stdlib.h header file.
The function system() can be used in following two ways:
- Passing a color code just to change the foreground of the text.
Syntax: system("COLOR <color code>");
Example: system("COLOR 4"); - Passing two color codes, one for background and one for foreground of the console.
Syntax: system("COLOR <color codeF><color codeB>");
color codeF is for foreground and
color codeB is for background.
Example: system("COLOR AC");
- /*
- Aditya's Console Color Changing Code Example
- Compiled On: MigGW (CODE::BLOCKS)
- This code will change the Foreground color of the console text.
- */
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- system("COLOR 6");
- printf("Welcome to the COLOUR changing Console Application!\n");
- return 0;
- }
/*Code to change Foreground and Background of console.*/
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
/*
Along with COLOR you can pass two codes
Here I have used F for Foreground and C for Background
*/
- system("COLOR FC");
- printf("Welcome to the COLOUR changing Console Application! \nThis code changes ForeGround and BackGround");
- return 0;
- }
Using system("COLOR FC") |
Color Codes:
0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White
*/
No comments:
Post a Comment
Thanks for feedback,
Your opinion will surely help me to enhance the quality of the content.