I'm on pset4/resize now and got an issue, my code works properly but can't pass check50. I used ~cs50/pset4/peek to check the header, it's all the same with the staff's implementation. I even created an 1x1 pixel bitmap image to check, and my code still worked well resizing it to 2x2, 3x3, 5x5 pixel bitmap image. Please help!

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
    for (int q = 0; q < n; q++)
        // iterate over pixels in scanline
        for (int j = 0; j < bi.biWidth; j++)
            // temporary storage
            RGBTRIPLE triple;

            // read RGB triple from infile
            fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
            for (int k = 0; k < n; k++)    
            // write RGB triple to outfile
                fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);

        // add padding
        for (int k = 0; k < paddingR; k++)
            fputc(0x00, outptr);
        // take the cursor back to the beginning of the scanline 
        if (q < n-1)
            fseek(inptr, -(bi.biWidth * sizeof(RGBTRIPLE)), SEEK_CUR);
    // skip over padding, if any
    fseek(inptr, padding, SEEK_CUR);

// close infile

// close outfile

// that's all folks
return 0;

1 Answer 1


You might want to retest with a different file. IF you test with a single 1x1 file, all you are really testing for is that the output file is the right size. It is possible, and likely, that every pixel in the new file will be the same as the single pixel in the original, BUT, it doesn't show that you are copying the correct pixels, as there is only one pixel. (I've seen this happen before.) If you test with a slightly larger file, like small.bmp, that has differing pixels, it validates that they are being copied, placed, and sized correctly.

Also, the info on whether your header is being processed correctly is vague. Have you compared the header of an input to an output file where the scaling factor is 1? They should be identical. Even then, the code could handle scale=1 headers correctly, but not when the scaling factor is larger. You also need to run a complex file through your program and through the staff program and compare the resulting two files using peek to compare the headers and xxd to compare the actual digital data contained in the files, and not simply look at the images (although if it's really off, the images will show it up fast).

This may not be an answer to "what's wrong", but it might give you an idea where to look.

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

  • Thank you so much. I've just resized small.bmp with the scaling factor is 1 then compared it with small.bmp and found the issue. I forgot to put bi.biHeight into abs() before multiply padding in the function of bi.biSizeImage and bf.biSize. That's why I can't pass the check only when the new padding isn't equal 0. Feb 24, 2016 at 14:36
  • Thanks! I had the same problem. Drove me almost insane.
    – user11391
    Apr 27, 2016 at 14:57

You must log in to answer this question.

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