Struct RGB

PHOTO EMBED

Sun Jun 09 2024 11:10:04 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c

#include <stdio.h>

// TODO: Declare Colour structure:
struct Colour
{
    unsigned char red;
    unsigned char green;
    unsigned char blue;
};

// TODO: Declare functions:
//struct Colour create_colour(...
struct Colour create_colour(unsigned char red, unsigned char green, unsigned char blue);
//void print_colour(...
void print_colour(struct Colour a_colour);

int main(void)
{
	print_colour(create_colour(255, 0, 0)); // RED
	print_colour(create_colour(0, 255, 0)); // GREEN
	print_colour(create_colour(0, 0, 255)); // BLUE
	print_colour(create_colour(255, 255, 0)); // YELLOW
	print_colour(create_colour(255, 0, 127)); // PINK

	return 0;
}

// TODO: Define functions:
struct Colour create_colour(unsigned char red, unsigned char green, unsigned char blue)
{
	struct Colour colour;
	colour.red = red;
	colour.green = green;
	colour.blue = blue;
	
	return colour;
}

void print_colour(struct Colour a_colour)
{
    printf("RGB: %u, %u, %u\n",a_colour.red,a_colour.green,a_colour.blue);
}
content_copyCOPY

Objective Given the incomplete C source code, your task is to declare and define appropriate structures and functions to work with colors. Program Components Declare Colour Structure: Declare a struct Colour with three unsigned char members named red, green, and blue. Declare and Define Functions: create_colour(unsigned char r, unsigned char g, unsigned char b): Takes three unsigned char parameters (r, g, b). Declares a local variable of type struct Colour. Assigns the values of r, g, and b to the appropriate members of the Colour structure. Returns the populated Colour structure. print_colour(struct Colour color): Takes a struct Colour as a parameter. Prints the color information in the specified format. Main Function: Calls create_colour multiple times with different arguments, saving the returned structures. Calls print_colour for each saved structure to display the color information. For example: Result RGB: 255, 0, 0 RGB: 0, 255, 0 RGB: 0, 0, 255 RGB: 255, 255, 0 RGB: 255, 0, 127