DIGIT-ARC read-only archive · snapshot: July 23, 2026

colors in c language...

4 posts · originally from https://geek.digit.in/community/threads/colors-in-c-language.32715/

tweety_bird_bunny
tweety_bird_bunny Original post #1
Jul 26, 2006 at 12:43 PM
plz tell me how can i change the background and forefround colors using c language im my programs.....
like if i want that the program dat i made on running shud display red color of text and green color in background....

is it possible....wat r the colors available and how to do it.....
Desmond
Desmond #2
Jul 26, 2006 at 1:24 PM
It is quite possible to do so in your programs. It can be done using the textcolor() and textbackground() functions. Put the integer value of the color between the brackets.

Both these functions can be found in "conio.h"
nithinks
Jul 26, 2006 at 10:09 PM
you can also insert blinking texts and backgrounds by the functions provided
in "graphics.h" header.... more info with example programs will be available in the HELP of turbo c editor.
tuxfan
tuxfan #4
Jul 27, 2006 at 11:23 AM
Are you doing this in GUI or older text based DOS type 25x80 interface?

If its the old type interface, I have all the functions and header files ready for the purpose :)) You have to straight away #include them and start using. :) I have made those files many years ago :p so all copyleft, free for use.

Example, colour.h:
Code:
/**************************
*
*   Foreground Colours
*
***************************/

#define BLACK       0
#define BLUE        1
#define GREEN       2
#define CYAN        3
#define RED         4
#define MAGNETA     5
#define BROWN       6
#define WHITE       7
#define GRAY        8
#define YELLOW     14  /*   Yellow, same as BRIGHT + BROWN    */

/*************************************************
*
*    To display in Blinking mode     add   BLINK
*    To display Brighter Characters  add   BRIGHT
*
*    e.g.  RED + BLINK
*          RED + BRIGHT + BLINK
*
*    Only foreground can be BRIGHT or BLINKing
*
***************************************************/

#define BRIGHT      8
#define BLINK     128


/*************************************************
*
*   Backgroud Colours
*
*   To display in a particular backgroud colour,
*   add it to foregroud colour
*
*   e.g.   RED + BACK_GREEN
*
**************************************************/

#define BACK_BLACK        0
#define BACK_BLUE        16
#define BACK_GREEN       32
#define BACK_CYAN        48
#define BACK_RED         64
#define BACK_MAGNETA     80
#define BACK_BROWN       96
#define BACK_WHITE      112