After edit:
For reference, here is the pseudocode from the walkthrough:
for each row
for each pixel
write to array n times
for n times
write array to outfile
write outfile padding
skip over infile padding
As I understand it, array
is going to hold one new row of RGBTRIPLE
s. The declaration would be RGBTRIPLE array[newbi.biWidth]
. You do not need sizeof(RGBTRIPLE)
because it is already a collection of RGBTRIPLE
objects.
This "new row" will be built horizontally ("write to array n times", which is the j
loop), and then written vertically ("for n times...", which is the l
loop). You always want to start building it at array[0]
and writing it from array[0]
. Therefore you need to reset counter3 to 0 before you start the next scanline.
There are some problems in the l
loop. To match the pseudo code it would be more like this:
for (int l = 0; l < n; l++)
{
fwrite......
write padding
}
fseek....
The fwrite
only needs to write array
to the outfile. You shouldn't iterate over the pixels, you already did that in the j
loop. And you need to write the whole array
.
fwrite(&array, sizeof(array),1,outfile)
is more like it.
Before edit: This fwrite(array, sizeof(RGBTRIPLE), newbi.biWidth, outptr);
always writes the calculated number of bytes from the first byte in array. Don't you need to reset counter3 = 0;
somewhere?