This is not a mistake in the lecture.
header contains enough space to hold
HEADER_SIZE bytes. You are probably thinking that it is being declared as an array of
unit8_t, which it is, but it will be an array within a contiguous space of memory--the entire array will exist without any other data interrupting it. Because of this, the start of the array is being accessed by calling
header without an index in the
fwrite functions. This is how strings (char arrays) are also referenced.
When the function executes, it will continue writing data to the variable specified until it runs out of space, avoiding the need for a loop to index through the
header array. Such a loop would not only be a lot more complicated to write, but no where near as clear to read. Because
header is the same size as the data being read (both of size
HEADER_SIZE), this will not result in any runtime errors.
Hopefully all of that makes sense. In my code, I wrote this as
fread(&header, HEADER_SIZE, 1, input); just to make it clear that it was using
header as a pointer to where it should store everything. I'm sure someone else could provide you with a better/more sophisticated explanation of why this works, but let me know if you want some more clarification. If this helps you understand what is going on, please accept the answer by clicking the check next to it.