I am trying to make a small C utility that reads in a MP3 tag from a file and displays it. I'm trying to make it as efficient as possible, so I'm making all of the char arrays that store the name, title, etc of the song dynamic, so they're sized at run time. I find the size of each 'frame' (a frame is: name, title, etc) through the MP3 ID3 header.
I am starting with the title of the song first. The MP3 file buffer that I loaded with the fopen operation and put into a char buffer looks like this for the title:
T|0|I|0|T|0|I|0|l|0|E,
all in hex of course. As you can see, there are 0's in between the letters of the title, thus in C, meaning a string terminator when trying to store in a char array.
I am trying the follwing:
memcpy( bBuffFirstFrame, &bBuffTag[0x0A+10], iFrameSize );
Where bBuffTag is where all of the ID3 title information is located.
Reading the documentation, it says that memcpy should store everything from the original buffer, including null terminators. However, the char array I am creating (bBuffFirstFrame) only stores the first byte and gets terminated because of the null terminator. So instead of storing the song name "N|0|A|0|M|0|E" (0 is a null), it stores only N.
bBuffFirstFrame is being defined as:
bBuffFirstFrame = ( unsigned char* ) malloc( iFrameSize );
So my first question is, is this the best way even to approach this problem? Should I use malloc to create dynamic arrays or should I just create an array thats really big for each frame? For example:
bBuffFirstFrame[10000]?
As you probably know, the song title changes with each MP3. Another reason I don't want to create a pre-defined size array is that it might cause a buffer overflow for a real big song name.
Final question, is there a way to store null terminators inside of a char array without terminating the string?
Sorry if this sounds confusing. Thanks!
'\0'characters have anything to do with the strings being in UNICODE?