ID3v2 ODD output

Posted 14 February 2013 - 06:36 PM

Hello everyone,

I am trying to write a code for my assignment in ID3 version 2 to read some data from an mp3 file. I found some information on the internet and I put together a program. I am beginner in programming and I can not find my mistake. The output is odd, the numbers of the version are not printed and also on the final print parts there are introduced some blank lines. I tried to flush it at the end maybe I was missing something in the buffer but the result is the same. Any help would be appreciated, thank you in advance for your time and effort to my question.

Replies To: ID3v2 ODD output

Re: ID3v2 ODD output

Posted 15 February 2013 - 07:08 AM

First: An overall comment. If a parameter or return value does not need a cast, do not cast it. By putting a cast you are telling compiler, I know what I'm doing trust me. So if you accidentally, put in an integer variable and cast it to a FILE* for a parameter that needs a FILE*, the compiler will go merrily along take your word for it that that integer value in the integer variable is a valid FILE pointer.

Next: That strncpy() should be a memcpy() or whatever your compiler's equivalent is. strncpy() will stop copying if there is a null terminator in the string. So if you had:

memory = { 1, 0, 2, 3 }

You will only end up with the 1 being copied into your header_id.

Next: You read in the major and minor version in lines 87-94, but you never read in the flags, that come before the size field.

Next: On line 102, you read in the size, but then you overwrite that value on lines 113-116. Assuming that you don't overwrite the values. You need to ensure that endianness of your target platform matches the endianess of the size that you just read from disk. As far as I know, ID3v2 tags are big endian. If you are running on an Intel processor, your platform is little endian, so you'll need to do some conversion.

I'll break off at this point since I've got to get back to work, but hopefully this gets you started. I recommend stepping through your code with a debugger to verify that you are getting the values you expect as the program runs, instead of just running the program and looking at the final output on the console.