I have these two structs:
typedef struct {
unsigned char r, g, b; // color components
char *code; // color code (char combination)
} Color;
typedef struct {
unsigned int width; // in pixels
unsigned int height; // in pixels
unsigned char cpp; // chars per pixel
unsigned int nof_colors; // number of colors
Color *colors; // reference to Color struct table
unsigned int *data[]; // holds `width` x `height` entries for `colors` codes
} XPM;
I then have a function that initializes a given XMP
struct:
void initXPM(XPM *image, unsigned int width, unsigned int height,
unsigned char cpp, unsigned int nof_colors) {
image.colors = [allocate memory for `nof_colors` Colors,
with each color having the length of `code` exactly `cpp`]
}
How can I allocate memory for the above struct member?