ADVERTISEMENT
ADVERTISEMENT

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?

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.

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.

conio.h - 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 - textbackground function Example in C

conio.h - 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

conio.h - textcolor() function Example 1 in C

conio.h - textcolor() function Example 2 in C

ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.