The exercise specifically asks for char parameters in the create_colour function for some reason.
I'm getting a compiler error along the lines of invalid conversion from 'char' to 'char' which i'm also unclear on.
Any help appreciated, thanks!
Code:
#include <stdio.h>
struct colour{
char red;
char green;
char blue;
};
struct colour create_colour(char r, char b, char g);
void printcolour(struct colour a);
int main(void)
{
struct colour red = create_colour(255, 0, 0);
//struct colour green =create_colour(0, 255, 0);
//struct colour blue =create_colour(0, 0, 255);
//struct colour yellow =create_colour(255, 255, 0);
//struct colour pink =create_colour(255, 0, 127);
printcolour(red);
return 0;
}
struct colour create_colour(char r, char b, char g)
{
struct colour x;
sprintf(x.red, r);
sprintf(x.green, g);
sprintf(x.blue, b);
return x;
}
void printcolour(struct colour a)
{
printf("RGB: %c, %c, %c\n", a.red, a.green, a.blue);
}