getbkcolor() function in C
Last Updated :
23 Jan, 2018
The header file graphics.h contains getbkcolor() function which returns the current background color.
Syntax :
int getbkcolor();
As getbkcolor() returns an integer value corresponding to the background color, so below is the table for Color values.
Colors Table :
COLOR INT VALUES
-------------------------------
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
When the background color is black:
#include <graphics.h>
#include <stdio.h>
int main()
{
int gd = DETECT, gm;
char arr[100];
initgraph(&gd, &gm, "" );
sprintf (arr, "Current background color = %d" ,
getbkcolor());
outtextxy(10, 10, arr);
getch();
closegraph();
return 0;
}
|
Output :
When the background color is other than black:
#include <graphics.h>
#include <stdio.h>
int main()
{
int gd = DETECT, gm;
char arr[100];
initgraph(&gd, &gm, "" );
setbkcolor(RED);
sprintf (arr, "Current background color = %d" ,
getbkcolor());
outtextxy(10, 10, arr);
getch();
closegraph();
return 0;
}
|
Output :
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...