I'm a newbie programmer and writing a simple wav-player as a pet project in C. Part of the file loading process requires reading specific data (sampling rate, number of channels, ...) from the file title. Currently what I am doing is like this:
- Scan for the sequence of bytes and leave it last
- Read 2 bytes in the variable
- Skip 4 bytes
- Read 4 bytes in the variable
- Check the value and return to error < / Li>
... and so on. (See code :)
I have written a number of helpful works to bite scanning / skipping / reading. Nevertheless, I am reading, checking, skipping the episode, which is neither too much Not only effective nor very smart. This is not a real issue for my project, but as it is a common task in handling binary files, I was wondering: Is there a pattern on how to do it more effectively with cleaner code?
Often, people define structures (often
#pragma pack (1) assurance against some padding) that matches the structure of the file, then they write something like
fread , and use the value from the structure.
Comments
Post a Comment