C textcolor()

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


void textcolor(int color);  #color must be written in all caps, or expressed as a interger value:

textcolor() Parameters: 

The textcolor() function takes a single parameter 'color' it is an integer variable that holds the corresponding integer value of a given color.

Parameter Description Required / Optional
color it has an integer value or  color must be written in all caps Required

 

Color Value
BLACK 0
BLUE 1
GREEN 2
CYAN 3
RED 4
MAGENTA 5
BROWN 6
LIGHTGRAY 7
DARKGRAY 8
LIGHTBLUE 9
LIGHTGREEN 10
LIGHTCYAN 11
LIGHTRED 12
LIGHTMAGENTA 13
YELLOW 14
WHITE 15

textcolor() Return Value

The textcolor() function does not return any value it just changes the text color.

Examples of textcolor()

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


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

int main()  
{  
   // setting the color of text
 textcolor(GREEN); /// You could type "2" instead of "GREEN", but it is not as readable

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

 getch();
 return 0;
}  

Output:


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

Example 2: How textcolor() works in C?


#include <stdio.h>
#include <conio.h>
int main()  
{
   textcolor(BLUE+BLINK);
   cprintf("Making text with a blue blinking text");
   getch();
   return 0;
}

Output:

Making text with a blue blinking text /* with blue blinking */