how does freed know to read one byte after another?
It's essentially the definition of fread():
size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );
Reads an array of count elements, each one with a size of size bytes, from the stream and stores them in the block of memory specified by ptr.
In your example
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
sizeof(RGBTRIPLE) is three bytes, so it will read from the
inptr stream, 3 bytes of data, and store it at the location pointed to by
Because you've got that
fread() inside of a loop, it will continue to read/store 3 bytes at a time for as many times as the value of
Is there a way to stop this behaviour and control it manually?
If you take it out of a loop, then it will only run once using the arguments you give it.
edited after correction
sizeof(RGBTRIPLE) is three bytes, but fread treats it as one element because it is a structure.