I'm utterly stuck on this pset. I don't want to give up on the course, but I've spent weeks and weeks looking on forums for help and I still have no idea where my code is going wrong. I'd really appreciate it if someone could take a look at what i've got so far and give me some pointers. Here is my code: https://gist.github.com/chicklet-goldsmith/1eaad870c7ce39d5ee39e68767f2519b

1 Answer 1


What's wrong with your programme? Does it fail on headers, on the bitmap, both? What have you tried, which unexpected results did you find? Write that in your question, and you will get better answers.

Looks like you write the correct headers. But you don't seem to understand, or did not intend to use the *= multiply-assign operator. The line

bio.biWidth = bi.biWidth *= n;

is performing two assignments. It works about as

bi.biWidth *= n; // multiply-assign
bio.biWidth = bi.biWidth;

just that the second assignment will not happen reading variable bi.biWidth, but directly the previously assigned value. In C, assignments (including combined assignments like *=) are expressions evaluating to the assigned value, and are executed from right to left.

So now both the old and the new header contain the scaled image size. To fix that, either use * instead of *=, or do bio.biWidth *= n; without mentioning bi.biWidth in that moment.

Oh, and make sure you get the right padding every time.

  • Thank you! I figured out the problem with the assignments and the padding just before I saw this. It works! Commented Dec 4, 2018 at 19:57

You must log in to answer this question.

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