#include #include #include #include char* get_file_contents(const char* filename) { FILE *fp = fopen(filename, "rb"); if (fp) { fseek(fp, 0, SEEK_END); int count = ftell(fp); char* contents = new char[count]; rewind(fp); fread(contents, 1, count, fp); fclose(fp); return contents; } throw errno; } #define READA(name, type, size) \ type name[size]; \ read_##type(name, size); \ printf(#name " = "); \ dump(name, size); \ puts(""); #define READ(name, type) \ type name; \ read_##type(&name, 1); \ printf(#name " = "); \ dump(name); \ puts(""); typedef int32_t Int32; struct reader { char* data; int at = 0; void read_Int32(int32_t* out, int count) { memcpy(out, &data[at], 4); at += 4; } void read_char(char* out, int count) { memcpy(out, &data[at], count); at += count; } void dump(int32_t v) { printf("%d", v); } void dump(char* v, int count) { for (int i = 0; i < count; i++) fputc(v[i], stdout); } }; struct myreader : reader { myreader() { data = get_file_contents("loop.wav"); READA(magic, char, 4); READ(size, Int32); } }; int main() { myreader(); }