I'm writing the code for resizing the image . I have an issue while using the fwrite
function.
fwrite( const void *buffer, size_t size, size_t count, FILE *stream );
From what I understand the parameter count
indicates how many times the value in buffer
must be written. However when I use it in the following manner,
fwrite(&triple, sizeof(RGBTRIPLE), n, outptr);
where n = 2
I get the following result:
0000036: 00ff00 000000 00ff00 000100 ............
0000042: 00ff00 000200 000000 000000 ............
000004e: 00ff00 000000 ffffff 000100 ............
000005a: 00ff00 000200 000000 000000 ............
0000066: 00ff00 000000 00ff00 000100 ............
0000072: 00ff00 000200 000000 000000 ............
Although, when I use a for loop construct for fwrite
:
for(int k = 0; k < n; k++) {
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
I get my desired output:
0000036: 00ff00 00ff00 00ff00 00ff00 ............
0000042: 00ff00 00ff00 000000 000000 ............
000004e: 00ff00 00ff00 ffffff ffffff ............
000005a: 00ff00 00ff00 000000 000000 ............
0000066: 00ff00 00ff00 00ff00 00ff00 ............
0000072: 00ff00 00ff00 000000 000000 ............
Why does substituting n
for count
return those odd hex values viz. 000100
, 000200
?