I am trying to store the RGB triples in the source file in an array, but I don't understand which variable type they are supposed to be. I have tried char, int, BYTE, unsigned long. The latter compiles, but when I run the code, the image gets resized properly, though with all black pixels...

So: what variable type must I declare my array to store?


It's actually a structure, or a struct that is defined in the bmp.h file:

 * This structure describes a color consisting of relative intensities of
 * red, green, and blue.

 * Adapted from http://msdn.microsoft.com/en-us/library/aa922590.aspx.
typedef struct
    BYTE  rgbtBlue;
    BYTE  rgbtGreen;
    BYTE  rgbtRed;
} __attribute__((__packed__))

You #include bmp.h in your code and define a single triple like this:

        RGBTRIPLE triple;

I'll let you figure out how to declare an array of triples. ;-)

Perhaps a review of the class material on the topic is in order?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Right. I actually tried that already as well, but I must have made a mistake while declaring the array or filling it. Thanks for the quick answer, I'll keep at it. Mar 19 '19 at 8:25
  • for (int m = 0; m < factor; m++) { triple = fread(&triple, sizeof(RGBTRIPLE), 1, inptr); bytes[j * factor + m].rgbtBlue = triple.rgbtBlue; bytes[j * factor + m].rgbtGreen = triple.rgbtGreen; bytes[j * factor + m].rgbtRed = triple.rgbtRed; } This little snippet doesn't work because the fread function returns an unsigned long and not a structure. How to I bridge the gap between this and the structure I want? Should I instead read the file 2 bytes at a time? Mar 19 '19 at 14:04
  • see cs50.stackexchange.com/a/31257/4847
    – Cliff B
    Mar 19 '19 at 20:42
  • Thanks again! I finally got it to work yesterday evening. Mar 20 '19 at 10:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .