In Pset4 resize(less), I try to resize the width of image by using fwrite. gain is integer I use for resize factor.
Originally I was doing like this. I put gain to the third argument of fwrite, and thought it would fwrite the read element "gain" times to achieve resize. However, the picture did magnify to the correct size, but the color is weird.
// write RGB triple to outfile
fwrite(&triple, sizeof(RGBTRIPLE), gain, outptr);
So I let the third argument back to 1, and use loop to implement, and the resize work as I want.
// write RGB triple to outfile
for (int k = 0; k < gain; k++) {
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
My question is why the result didn't go the way I want when I use the third argument of fwrite to control resize value? Did I misunderstand something?