PSET4/resize (more) what's wrong with my code?

I did the less comfortable one and so I'll solve it with you. I'm not exactly sure what to do right now but one thing I noticed in your code:

    // iterate over pixels in scanline
    for (int j = 0; j < biOld.biWidth; j++)
    {
        // temporary storage
        RGBTRIPLE triple;

        // read RGB triple from infile
        fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

        if (j < bi.biWidth)
        {
            // write RGB triple to outfile
            for (int l = 0; l < factor; l++)
            {
                fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
            }
        }
    }

Let's say, you want to downscale by factor = 0.5, and your old image dimensions are 4x4 and the new one is 2x2.

Your first for loop is iterating over the old dimensions (pixel index 0, 1, 2, 3) but due to that if condition, you're writing only 0, 1 pixel indices of the old image in the outptr (but you actually want indices 0 and 2). Also, I'm not sure what that l for loop is doing because what happens if the factor is < 0?

/r/cs50 Thread