I am in week 4 of Harvard's CS50. I am currently working on Resize - so enlarging an existing BMP by a particular factor (between 1 and 100).
My code compiles and resizes the image accurately, however when running CS50's Check50 it indicates unexpected errors in the bfSize field, e.g. expected 0xae, not 0x5a in header field bfSize.
I am completely new to programming so forgive me for any stupid questions.
This is a link to my code: https://raw.githubusercontent.com/me50/NinaIMW/cs50/problems/2019/x/resize/less/resize.c?token=ALYWHW7TNZRPFYTB73JSUCK5LBMXC
This is what Check50 returns when I test my code:
:) resize.c and bmp.h exist.
:) resize.c compiles.
:) doesn't resize small.bmp when n is 1
:( resizes small.bmp correctly when n is 2
expected 0xae, not 0x5a in header field bfSize
:( resizes small.bmp correctly when n is 3
expected 0x132, not 0x5a in header field bfSize
:( resizes small.bmp correctly when n is 4
expected 0x1e6, not 0x5a in header field bfSize
:( resizes small.bmp correctly when n is 5
expected 0x306, not 0x5a in header field bfSize
:( resizes large.bmp correctly when n is 2
expected 0x6f6, not 0x1e6 in header field bfSize
:( resizes smiley.bmp correctly when n is 2
expected 0x336, not 0xf6 in header field bfSize
:( resizes smiley.bmp correctly when n is 3
expected 0x6f6, not 0xf6 in header field bfSize```
I don't have small.bmp (so I can't try) but I would suggest to change :
newBf.bfSize = bi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
to
newBf.bfSize = newBi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
You were still using the old bi
instead of newBi
to calculate the newBf.bfSize
.