I'm beginning to wrap my head around the week 4 problem set, and I'm confused about how the fread and fwrite functions work.
As I understand it, fread tells the computer to copy data into RAM, and fwrite tells it to write data to a file, which is pointed to with something like "&buffer", such as in the distribution code for week 4's lab, Volume:
Considering an example from the distribution code for filter:
// Copy header from input file to output file
uint8_t header[HEADER_SIZE];
fread(header, HEADER_SIZE, 1, input);
fwrite(header, HEADER_SIZE, 1, output);
// Read samples from input file and write updated data to output file
uint16_t buffer;
while (fread(&buffer, sizeof(uint16_t), 1, input))
{
buffer = buffer * factor;
fwrite(&buffer, sizeof(uint16_t), 1, output);
Assuming I understand basically what's happening when the fread and fwrite functions are called - How is it that in the above example, the second time fwrite is called it doesn't overwrite the data already stored at the beginning of the file "output", aka the header? How does it know to start with the 45th byte? (the header size is 44 bytes).