I\'m making a program that creates a bitmap file in C. it\'s using 24-bit colour.
I\'m writing the file in 3 stages, i first write the FileHeader, then the InfoHeade
You are not padding rows to word size, you are padding the current file position. And it doesn't work because the size of your headers add up to 54 -- not a multiple of 4.
Instead of using ftell to retrieve the 'current position', use maths. Make your pad
an unsigned long, and insert before your loops:
int npad = (sizeof(IMAGE)*width) & 3;
if (npad)
npad = 4-npad;
Then, instead of the while(ftell ..
loop, write out the number of required bytes immediately:
fwrite (&pad, 1,npad, n_img);
npad
will range from 0..3, that's why you have to make pad
a 4-byte integer.