Home »
C programs »
conio.h header file functions
textcolor() and textbackground() functions of conio.h in C
In this article, we are going to learn about the textbackground() and textcolor() functions of conio.h header file and use them to change colors.
Submitted by Manu Jemini, on March 15, 2018
These are very helpful functions to change the color or the background of the text. How this works is first we got to set the color of the text and then print something on the console?
<conio.h> - textbackground() function in C
To use the textbackground() function all you need to do is before printing any text call this function with a parameter defining the color in capital letters. That will be enough to change the background color of the text.
textbackground() function Example in C
#include <stdio.h>
// to use 'textbackground'
#include <conio.h>
int main() {
// setting the color of background
textbackground(GREEN);
// message
cprintf("Change the background color to green");
getch();
return 0;
}
Output
<conio.h> - textcolor() function in C
Now, if you want your text to blink then while calling the textcolor() function pass the color and also say BLINK. This will like this: textcolor(BLUE+BLINK).
These are the function of the conio.h file and must be included in your program.
textcolor() function Example in C
#include <stdio.h>
// to use 'textcolor()'
#include <conio.h>
int main() {
// set the color of text
textcolor(BLUE);
// message
cprintf("Color of text is BLUE\n\n");
// set blinking color
textcolor(GREEN + BLINK);
// message
cprintf("\nThis is BLINKING text");
getch();
return 0;
}
Output