I'm looking over my resize code rn, but have been stuck for a while now, was wondering if anyone could point me in the right direction. The resized images have colors beside green, which I would guess it's reading garbage values and outputting them, which likely point to my fseek() function not resetting to the beginning of the original picture line properly? I've removed the header file rewriting part as I've already used the cs50 commands to compare and they haven't thrown any errors so far.

Thank you!

int intpadding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int intwidth = bi.biWidth;
int intheight = abs(bi.biHeight);

// iterate over infile's scanlines
float h = 1;
float w = 1;
long reset = (intwidth*sizeof(RGBTRIPLE) + intpadding);

for (int i = 0; i < intheight; i++)
    h += f;
    while(h > 1){
    // iterate over pixels in scanline
        //fseek(outptr, bi.biWidth*-1, SEEK_CUR);
        for (int j = 0; j < intwidth; j++){
        // temporary storage
            RGBTRIPLE triple;

        // read RGB triple from infile
            fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
            w += f;
            while (w >1){
        // write RGB triple to outfile
                fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);

        // then add it back (to demonstrate how)
        for (int k = 0; k < finpadding; k++)
            fputc(0x00, outptr);
        fseek(inptr, -reset, SEEK_CUR);
    fseek(inptr, intpadding, SEEK_CUR);

1 Answer 1


Too many one letter variables for me to really understand your code. But reset probably should not include intpadding.

And the j++ within the innermost loop also is quite odd.

  • Oh my god thank you so much, yes the j++ was an error, skipping certain pixels as well as the reset, since I was skipping over the initial padding after I wrote the lines.
    – Jeff Guan
    Commented Aug 18, 2017 at 13:47

You must log in to answer this question.

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