Hi I know this has been asked many times as I've already checked with many similar threads. I have checked for many more hours on my code but still can't figure out what is wrong. Can anyone take a look at my code please? Thanks!

[mod: code hidden behind edit flag - per academic honesty rules]

I've put a lot of thought into the unit of bfSize & biSizeImage, and I think I've got it correct, including the unit & padding:

    jharvard@appliance (~/Dropbox/CS50/pset4/bmp): ./resize 1 ./blue/1x1rev.bmp ./student/1-1235.bmpjharvard@appliance (~/Dropbox/CS50/pset4/bmp): ~cs50/pset4/peek ./blue/1x1rev.bmp ./student/1-1235.bmp
offset  type   name              argv[1]   argv[2]
0       WORD   bfType               4d42      4d42
2       DWORD  bfSize           0000003a  0000003a
6       WORD   bfReserved1          0000      0000
8       WORD   bfReserved2          0000      0000
10      DWORD  bfOffBits        00000036  00000036
14      DWORD  biSize           00000028  00000028
18      LONG   biWidth          00000001  00000001
22      LONG   biHeight         ffffffff  ffffffff
26      WORD   biPlanes             0001      0001
28      WORD   biBitCount           0018      0018
30      DWORD  biCompression    00000000  00000000
34      DWORD  biSizeImage      00000004  00000004
38      LONG   biXPelsPerMeter  00000000  00000000
42      LONG   biYPelsPerMeter  00000000  00000000
46      DWORD  biClrUsed        00000000  00000000
50      DWORD  biClrImportant   00000000  00000000

But still I can't pass most of the check50 :(

jharvard@appliance (~/Dropbox/CS50/pset4/bmp): check50 2014.fall.pset4.resize bmp.h resize.c
:) resize.c and bmp.h exist
:) resize.c compiles
:( doesn't resize 1x1-pixel BMP when n is 1
:( resizes 1x1-pixel BMP to 2x2 correctly when n is 2
:( resizes 1x1-pixel BMP to 3x3 correctly when n is 3
:) resizes 1x1-pixel BMP to 4x4 correctly when n is 4
:( resizes 1x1-pixel BMP to 5x5 correctly when n is 5
:) resizes 2x2-pixel BMP to 4x4 correctly when n is 2

Are you sure about your placement of the following lines:

        // add padding to outfile
        for (int l = 0; l < padding_new; l++)
            fputc(0x00, outptr);

It looks to me like they might be included inside the loop that is commented // iterate over pixels in scanline. If this is true, when and how often are these lines being executed?

In case you are unsure of how the padding works, there is some great information in the spec http://cdn.cs50.net/2015/x/psets/4/pset4/pset4.pdf , an excerpt of which is pasted here for you:

And so the scanline is "padded" with as many zeroes as it takes to extend the scanline’s length to a multiple of 4. In other words, between 0 and 3 bytes of padding are needed for each scanline in a 24-bit BMP.

Depending on where you put your code for handling padding (i.e. which loops it is inside) you might be adding padding too frequently, or not frequently enough.

I think this should be enough information to help you find the answer on your own, but if you find it confusing, let me know, and I'll be more explicit. I might be wrong, after all.


If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark.

  • Thank you so much ... I've been looking all over the codes so many times without spotting this small error. Sep 15 '15 at 9:37

You must log in to answer this question.

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