I'm using fwrite
to write a file (it's an image).
First, I'm writing a header that has a fixed size
int num_meta_write_bytes = fwrite(headerBuffer, 1, headerSize, file);
This works OK
Then I have to write the pixels:
num_write_bytes = fwrite(data_pointer, 1, image_size, file);
This works OK
For my case, I have to write a variable number of zeros between the header and the pixels, the (ugly?) solution I found is:
for (size_t i = 0; i < padding_zeros; i++) //padding_zeros is calculated in runtime
{
uint8_t zero = 0;
num_meta_write_bytes += fwrite(&zero, 1, sizeof(uint8_t), fp);
}
(This code is placed before writing the pixels)
My question is: is there a way to directly tell fwrite
to continously write the same value padding_zeros
times? instead of using this for
loop?