C textbackground()

The textbackground() function is defined in the conio.h header file. This function helps to change the background colour of printed text.


void textbackground(int color);  #Where color is a integer variable


textbackground() Parameters: 

The textbackground() function takes a single parameter 'color' it is a integer variable which holds the corresponding integer value of a given colour.

Parameter Description Required / Optional
color it has a integer value Required

textbackground() Return Value

The textbackground() function does not return any value it just change the text background.

Examples of textbackground() 

Example 1: Working of textbackground() function in C?


#include <stdio.h>
#include <conio.h>

int main()  
{  
   // setting the background color of text
 textbackground(GREEN);

 cprintf("Change the text background colour to green");

 getch();
 return 0;
}  

Output:


Change the text background colour to green /* with green background colour */

Example 2: How textbackground() works in C?


#include <stdio.h>
#include <conio.h>
int main()  
{
   textbackground(RED);
   cprintf("and the answer is 42 with a red background.");
 
   getch();
   return 0;
}

Output:

and the answer is 42 with a red background