#include
#include
struct color
{
int red;
int green;
int blue;
};
struct color your_color;
struct color* p = &your_color;
struct color const MEGENTA = { .red = 255, .green=0, .blue = 255 };
struct color* q = &MEGENTA;
struct color brighter;
struct color* p_brighter=&brighter;
void check_color(int your_color);
struct color* make_color(int your_red, int your_green, int your_blue);
int get_red(struct color* p);
bool equal_color(struct color* p, struct color* q);
int revise_color(int your_color);
struct color* bighter_color(struct color* p);
int main(void)
{
int your_red, your_green, your_blue;
printf("Please enter red,green and blue:");
scanf_s("%d %d %d", &your_red, &your_green, &your_blue);
make_color(your_red, your_green, your_blue);
printf("This is your color:n");
printf("red:%dn", p->red);
printf("green:%dn", p->green);
printf("blue:%dn", p->blue);
printf("GetRed:%dn", get_red(p));
if (equal_color(p,q)==true)
{
printf("Equal!n");
}
else
{
printf("Not equal!n");
}
bighter_color(p);
printf("This is the brighter color:n");
printf("brighter red:%dn", p_brighter->red);
printf("brighter green:%dn", p_brighter->green);
printf("brighter blue:%dn", p_brighter->blue);
return 0;
}
struct color* make_color(int your_red, int your_green, int your_blue)
{
(void)check_color(&your_red);
(void)check_color(&your_green);
(void)check_color(&your_blue);
p->red = your_red;
p->green = your_green;
p->blue = your_blue;
return p;
}
void check_color(int *your_color)
{
if (*your_color<0)
{
*your_color = 0;
return;
}
if (*your_color>255)
{
*your_color = 255;
return;
}
}
int get_red(struct color* p)
{
return p->red;
}
bool equal_color(struct color* p, struct color* q)
{
if (p->red==q->red)
{
if (p->green==q->green)
{
if (p->blue==q->blue)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
return false;
}
struct color* bighter_color(struct color* p)
{
if (p->red==0&&p->green==0&&p->blue==0)
{
p_brighter->red = 3;
p_brighter->green = 3;
p_brighter->blue = 3;
return p_brighter;
}
p_brighter->red=revise_color(p->red);
p_brighter->green = revise_color(p->green);
p_brighter->blue = revise_color(p->blue);
return p_brighter;
}
int revise_color(int your_color)
{
if (your_color<3&&your_color>0)
{
return 4;
}
if ((int)(your_color/0.7)>255)
{
your_color = 255;
return your_color;
}
return (int)(your_color / 0.7);
}



