Question
Complete the color2.c program. Note that: color has a member representing the name. Its assumed that name is no more than 25 characters. It can
Complete the color2.c program. Note that:
color has a member representing the name. Its assumed that name is no more than 25 characters.
It can hold multiple colors in an array of color structures. Its assumed that there are no more than 100 colors to be held.
Complete the functions
insert: It allows the user to enter the name, the red, green, and blue member values and store them in the array of color structures. It will check whether the color being added has already existed.
search: It should also allow user to look up a colors RGB values by name.
color2.c program provided below:
#include "readline.h" #include
struct color{ char name[NAME_LEN+1]; int red; int green; int blue; };
struct color brighter(struct color c); struct color make_color(int red, int green, int blue); void print(struct color colors[], int nc); void insert(struct color colors[], int *nc); void search(struct color colors[], int nc);
int main() {
char code; struct color cols[MAX_COLORS]; int num_colors = 0;
for (;;) { printf("Enter operation code: "); scanf(" %c", &code); while (getchar() != ' ') /* skips to end of line */ ; switch (code) { case 'i': insert(cols, &num_colors); break; case 's': search(cols, num_colors); break; case 'p': print(cols, num_colors); break; case 'q': return 0; default: printf("Illegal code "); } printf(" "); }
return 0; }
/*insert a color to the array */ void insert(struct color colors[], int *nc) { if (*nc == MAX_COLORS) { printf("Database is full; can't add more parts. "); return; }
//add your code here
} /*display the colors stored in the array*/ void print(struct color colors[], int nc) {
int i;
printf("Color\tRed\t" "Green\tBlue "); for (i = 0; i < nc; i++) printf("%s\t%d\t%d\t%d ", colors[i].name, colors[i].red, colors[i].green, colors[i].blue); } /*search a color by name and display the RGC if found */ void search(struct color colors[], int nc) { //add your code here
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started