Maybe a long shot, but has anyone already did CS50's Resize problem?

My code (see gist) is almost functional, but it doesn’t fully copy the white pixels. Here’s the comparison:



Any hints would be really appreciated. Thanks!

I think you’re “overreading” the triples from the infile.

Have you watched the walkthrough yet?


Yes, I already watched the walkthrough a couple of times. And the material is still going wayyyy over my head :frowning:

I think you’re “overreading” the triples from the infile.

fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

 // Write each pixel "scale" times.
for (int z = 0; z < scale; z++)
    fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);

How do I fix it then? As I’m looking at it, I don’t think I’m overreading the triples because I’m not freading it scale times (unlike fwrite). Please do enlighten me :smiley:

You’re reading more scanlines from the infile than it has, because it only has r rows, but you’re really reading r * scale rows (the code that reads from the infile is in the loop that writes each row “scale” times).