In copy.c, in case we're copying a 3x3 bmp image, this piece of code adds the calculated padding to the bmp

// then add it back (to demonstrate how)
for (int k = 0; k < padding; k++)
    fputc(0x00, outptr);

I believe that we're adding a hexadecimal value (3 Bytes), but per the fputc() man page

fputc() writes the character c, cast to an unsigned char, to stream.

Now, the size of an unsigned char is a byte. So how does fputc() manage to put 3 Bytes?


What it does, Kareem, is it puts one byte with every iteration of the loop. padding is equal to 3 (i.e., 3 bytes) in this case! :)

  • Totally forgot about the loop! :) – Kareem Jun 27 '14 at 21:25

fputc(0x00, output); really puts a single char.

0x00 in hexadecimal is exactly one byte. the 0x is not part of the number, it just indicate that the number is in fact hexadecimal.

Would be good clarify that, the padding in the example image is really == 1 (1 byte), at the end of each scanline. Since there are 3 vertical lines so there are a total of 3 bytes, but they are not written together in the same line.

If the image was 2x3, there would be padding == 2, per line. With a total of 6.

  • You're right! I was just a little bit confused! This is not a typical answer though, please either edit it or post it as a comment! Thank you! – Kareem Jun 27 '14 at 21:38
  • This was my first answer here at stackexchange. I edited it a bit, please, tell why its not a typical one. thanks for the advice. – Felipe Amaral Jun 27 '14 at 21:55
  • Welcome to the SE community! That was before the edit! It's better now! – Kareem Jun 27 '14 at 21:56

You must log in to answer this question.

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