I am having trouble reading in data from a file. The data file store the information of albums and its respective track info
eg
1234 //this is id number
Scarlets Walk //album name
Tori Amos //artist
24 //price
2 //stock
Pop //genre
Track A //track name
10 30 //track length in mins and secs
Track B
5 0
Track C
3 15
Each album can have up to 20 tracks, however im just using a data file with 3 per album for initial testing. The problem i am having is that i cannot get my read in function (which worked when there was no track data) to read in the album and its respective track data.
Here is the relevant code. I am not sure how to create the loops since different albums would have different amounts of tracks.
struct tracklist
{
char trackName[32];
int trackMins;
int trackSecs;
};
struct albums
{
char idNo[10];
char albumName[32];
char artistName[32];
tracklist tracks;
float price;
int stock;
char genre[32];
};
albums cdstock[Arraysize];
int YourLoadDB()
{
int i = 0;
ins.open("CDSample.txt", ios::in);
if(ins.good())
{
while ((ins.good()) && (i < Arraysize))
{
ins >> cdstock[i].idNo;
ins.clear();
ins.ignore(100,'\n');
ins.getline(cdstock[i].albumName, 256);
ins.getline(cdstock[i].artistName, 256);
ins >> cdstock[i].price;
ins >> cdstock[i].stock;
ins.clear();
ins.ignore(100,'\n');
ins.getline(cdstock[i].genre, 256);
ins.clear();
ins.ignore(100,'\n');
for (int x = 0; x < 3; x++)
{
ins.getline(cdstock[x].tracks.trackName, 256);
ins.clear();
ins.ignore(100,'\n');
ins >> cdstock[x].tracks.trackMins >> cdstock[x].tracks.trackSecs;
ins.clear();
ins.ignore(100,'\n');
}
i++;
}
}
else
{
cout << "File does not exist!" << endl;
}
numrec = i-1;
cout << "The amount of records loaded is: " << numrec << endl;
return i;
ins.close();
}