Because you try to read from an write-only file handle. Read into hdr
with the first fread
call. No need for the buf
array (or a second read):
Header hdr;
/* Opening files ... */
fread(&hdr, 1, 64, input);
fwrite(&hdr, 1, 64, output);
printf("\n>>> %4.4s", hdr.ChunkId);
/* ... */
Also note that hdr.ChunkID
will not be terminated as a string, so printing it as a string might print seemingly random characters after the header. This is why I added field length and precision in the printf
call.