I'm new to C programming and I am trying to write a simple ID3 tag editor for mp3s. An id3v1 tag is the last 128 bytes of the file, with 30 characters for the artist, 30, for the title, etc...
So far I have written this program which saves each tag to a separate string displays the tags:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char title[30];
char artist[30];
char album[30];
char year[4];
char comment[30];
FILE *fp;
//OPEN FILE
fp = fopen("test.mp3", "rb");
//GO TO TITLE BLOCK & READ
fseek(fp, -125, SEEK_END);
fread(title, 30, 1, fp);
printf("Title: "); puts(title);
//GO TO ARTIST BLOCK & READ
fseek(fp, 0, SEEK_CUR);
fread(artist, 30, 1, fp);
printf("Artist: "); puts(artist);
//GO TO ALBUM BLOCK & READ
fseek(fp, 0, SEEK_CUR);
fread(album, 30, 1, fp);
printf("Album: "); puts(album);
//GO TO YEAR BLOCK & READ
fseek(fp, 0, SEEK_CUR);
fread(year, 4, 1, fp);
year[4] = '\0' ;
printf("Year: "); puts(year);
//GO TO COMMENT BLOCK & READ
fseek(fp, 0, SEEK_CUR);
fread(comment, 30, 1, fp);
printf("Comment: "); puts(comment);
printf("\n\n\n");
system("pause");
return 0;
//END MAIN
}
From what i've read so far I think I can use the one file pointer I have to read from and write to the file if I use the "r+b" argument in my fopen function.
It shouldn't be hard for me to add something to the program that would let the user rename each string, but I don't know how i would go about writing the changed strings back to the file. Any help would be appreciated.
I am also having an issue with the year string. It is 4 bytes long and when i try to print my year string it prints the 4 character long year string, plus the album string next to it (which is why I added the " year[4] = '\0' ; " code. I'm guessing the fread function doesn't add the \0 character to the end of the string?
Here is the mp3 file i'm working with: