Hello, im trying to write a program that will read the id3v1 tag of an mp3 file, output the current information, and then allow the user to edit the ID3 tag. I can get it to output the information but I'm having some issues getting it to edit correctly.

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int end;

    ifstream myInputFile;

    myInputFile.open("01-Cheeseburger in Paradise.mp3", ios::in);

    if(!myInputFile.good())
    {
        cout << "!!!";
        system("PAUSE");
        return 0;
    }

    myInputFile.seekg(0,ios::end);

    end = myInputFile.tellg();

    //go to the TAG

    myInputFile.seekg(end - 128);

    char tag[4];
    for(int i = 0; i < 3; i++)
    {
        tag[i] = myInputFile.get();
    }
    tag[3] = '\0';

    char title[31];
    for(int i = 0; i < 30; i++)
    {
        title[i] = myInputFile.get();
    }
    title[30] = '\0';
    cout << "Title: " << title << endl;

    char artist[31];
    for(int i = 0; i < 30; i++)
    {
        artist[i] = myInputFile.get();
    }
    artist[30] = '\0';
    cout << "Artist: " << artist << endl;

    char album[31];
    for(int i = 0; i < 30; i++)
    {
        album[i] = myInputFile.get();
    }
    album[30] = '\0';
    cout << "Album: " << album << endl;

    char year[5];
    for(int i = 0; i < 4; i++)
    {
        year[i] = myInputFile.get();
    }
    year[4] = '\0';
    cout << "Year: " << year << endl;

    char comment[29];
    for(int i = 0; i < 28; i++)
    {
        comment[i] = myInputFile.get();
    }
    comment[28] = '\0';
    cout << "Comment: " << comment << endl;

    char zero = myInputFile.get();
    zero ?  cout << "Zero track not listed\n" : cout << "Zero track is stored\n";

    char track = myInputFile.get();
    cout << "Track: " << (int)track << endl;

    char genre = myInputFile.get();
    cout << "Genre: " << (int)genre << endl;

    myInputFile.close();

    ofstream myOutputFile;

    myOutputFile.open("01-Cheeseburger in Paradise.mp3", ios::app);

    if(!myOutputFile.good())
    {
        cout << "!!!";
        system("PAUSE");
        return 0;
    }

    myOutputFile.seekp(0,ios::end);

    end = myOutputFile.tellp();

    cout << end << "}{}{}{}" << endl;


    //go to the TAG
    int putPtr = end-128;
    myOutputFile.seekp(putPtr);

    char change;
    putPtr += 3;
    myOutputFile.seekp(putPtr);

    cout << "|||" << putPtr << endl;

    cout << "Would you like to change song title?(y or n)" << endl;
    cin >> change;
    if(change == 'y')
    {
        cout << "Enter new song title" << endl;
        cin >> title;
        for(int i = 0; i < 30; i++)
        {
            myOutputFile.put(title[i]);
        }
    }

    putPtr += 30;
    myOutputFile.seekp(putPtr);

    cout << "|||" << putPtr << endl;

    cout << "Would you like to change the artist?(y or n)" << endl;
    cin >> change;
    if(change == 'y')
    {
        cout << "Enter new song artist" << endl;
        cin >> artist;
        for(int i = 0; i < 30; i++)
        {
            myOutputFile.put(artist[i]);
        }
    }
    else if(change == 'n')
    {
        putPtr += 30;
        myOutputFile.seekp(putPtr);
    }

    cout << "|||" << putPtr << endl;

    cout << "Would you like to change album value?(y or n)" << endl;
    cin >> change;
    if(change == 'y')
    {
        cout << "Enter new album info" << endl;
        cin >> album;
        for(int i = 0; i < 30; i++)
        {
            myOutputFile.put(album[i]);
        }
    }
    else if(change == 'n')
    {
        putPtr += 30;
        myOutputFile.seekp(putPtr);
    }

    cout << "|||" << putPtr << endl;

    cout << "Would you like to change year?(y or n)" << endl;
    cin >> change;
    if(change == 'y')
    {
        cout << "Enter song year" << endl;
        cin >> year;
        for(int i = 0; i < 4; i++)
        {
            myOutputFile.put(year[i]);
        }
    }
    else if(change == 'n')
    {
        putPtr += 4;
        myOutputFile.seekp(putPtr);
    }

    cout << "|||" << putPtr << endl;

    cout << "Would you like to change comment?(y or n)" << endl;
    cin >> change;
    if(change == 'y')
    {
        cout << "Enter new comment info" << endl;
        cin >> comment;
        for(int i = 0; i < 28; i++)
        {
            myOutputFile.put(comment[i]);
        }
    }
    else if(change == 'n')
    {
        putPtr += 28;
        myOutputFile.seekp(putPtr);
    }

    cout << "|||" << putPtr << endl;

    putPtr += 1;

    cout << "|||" << putPtr << endl;

    cout << "Would you like to change the track number?(y or n)" << endl;
    cin >> change;
    if(change == 'y')
    {
        cout << "Enter new track number" << endl;
        cin >> track;
        myOutputFile.put(track);
    }
    else if(change == 'n')
    {
        putPtr += 1;
        myOutputFile.seekp(putPtr);
    }

    cout << "|||" << putPtr << endl;

    cout << "Would you like to change the songs genre?(y or n)" << endl;
    cin >> change;
    if(change == 'y')
    {
        cout << "Enter new genre number" << endl;
        cin >> genre;
        myOutputFile.put(genre);
    }
    else if(change == 'n')
    {
        putPtr += 1;
        myOutputFile.seekp(putPtr);
    }

    cout << "|||" << putPtr << endl;

    myOutputFile.close();


    system("PAUSE");
}

any help would be greatly appreciated

Maybe a simple example will point you in the right direction...

#include <iostream>
#include <fstream>
using namespace std;
#define MP3FILE  "01-Cheeseburger in Paradise.mp3"


int main(void)
{
    char title[31] = {0};
    ofstream myOutputFile;
    streamoff pos;

    myOutputFile.open(MP3FILE,  ios::out | ios::in | ios::binary);
    if(!myOutputFile.good())
    {
        cout << "myOutputFile open failed";
        system("PAUSE");
        return 0;
    }

    myOutputFile.seekp(0,ios::end);
    pos = myOutputFile.tellp();
    //go to the TAG
    pos -= 128;
    myOutputFile.seekp(pos);
    pos += 3;
    myOutputFile.seekp(pos);
    memset(title, 0,  sizeof title);
    strcpy(title, "TESTING");
    myOutputFile.write(title, sizeof(title) - 1  );
    myOutputFile.close();
    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.