0

I don't understand why my code doesn't work the way i expected it, i believe my mistake is in understanding fseek. please help me with some advice

int scanline = 0;
int horiz = 0;

for(int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    horiz = 0;
    for(int j = 0; j < bi.biWidth; j++)
    {
        RGBTRIPLE rgbt;

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

        for(int k = 0; k < n; k++)
        {
            fwrite(&rgbt, sizeof(RGBTRIPLE), 1, outptr);
        }
        horiz++;
    }

    fseek(inptr, padding_ori, SEEK_CUR);

    for(int p = 0; p < padding; p++)
    {
        fputc(0x00, outptr);
    }

    scanline++;
    if(scanline != n)
    {
        fseek(inptr, 0 - padding_ori - horiz, SEEK_CUR);
    }
    else
    {
        scanline = 0;
    }
}
0
2
fseek(inptr, 0 - padding_ori - horiz, SEEK_CUR);

Interesting way to do this. When the loop finishes, isn't horiz equal to bi.biWidth?

Now, when you call fseek(), what units does it use to move? Maybe bytes? And what units do bi.biWidth and (since they're equal) horiz use?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

2
  • Thanks Cliff!, it's (kind of) worked now. now the issue is, it only copied 3 row of the image, it never fully copied the image vertical-wise. Mar 14 '16 at 8:51
  • oh, i already found the solution, by decrementing the i loop if scanline not equal to n. Thanks for the help cliff !! :D Mar 14 '16 at 8:59

You must log in to answer this question.

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