I am trying to parse a .wav file header. If I remove the chunk_size +=...
line, i get the expect result: RIFF
, but once I add that line, I get RIFFÄÿÿÿ
. Why is every value added to chunk_size
apparently "appended" to chunk_id
? How can chunk_id
have more than four elements? Is there something basic about arrays or binary data that I don't understand? Is it inappropriate to use cout
on a char array?
struct Wave
{
Wave (FILE* file) {
char header[44];
uint size = fread(header, sizeof(char), 44, file);
chunk_size = 0;
for (uint i = 0; i < 4; i ++) {
chunk_id[i] = header[i];
chunk_size += header[i + 4] * pow(16, i);
}
cout << chunk_id;
}
char chunk_id[4];
uint chunk_size;
char format[4];
...
...
...
};