The resize assignment has had me spinning in circles for the past few weeks. Could someone give me an example of how to use fseek and point out the logic errors in my code?
for (int i = 0, biHeight = abs(original_height); i < biHeight; i++)
{
for (int l = 0; l < n; l++)
{
// iterate over pixels in scanline
for (int j = 0; j < original_width; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
if (i == 0)
{
fseek(inptr, 54, SEEK_SET);
}
else
{
fseek(inptr, (int)&triple, SEEK_CUR);
}
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to outfile
if (i == 0)
{
fseek(outptr, 54, SEEK_SET);
}
else
{
fseek(outptr, (int)&triple * n, SEEK_CUR);
}
for (int m = 0; m < n; m++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// skip over padding, if any
fseek(inptr, infile_padding, SEEK_CUR);
// then add it back (to demonstrate how)
for (int k = 0; k < outfile_padding; k++)
{
fputc(0x00, outptr);
}
fseek(outptr, outfile_padding, SEEK_CUR);
}
}