hi,
i'm in the process of coding a piece of software to list my cd audio collection using a binary search tree, so far i've not ran into many difficulties. As an addition to the program i want to be able to add to the list when i get a new cd, the list is saved to a text file when i shut down the program and gets loaded up when the program starts
heres the code thats giving me problems:
FILE *fp;
printf("\n\nPlease enter the name of the file to open - ");
gets(filename);
sprintf(pathname, "d:\\college stuff\\ads\\merit\\%s.txt",filename);
if((fp = fopen(pathname, "r"))==NULL)
{
printf("Cant find file, press any key to return to the Options Menu");
getche();
}
else
{
while(!feof(fp))
{
fscanf(fp,"%[^|]|%[^|]|%d|", data.artist, data.title, &data.numberTracks);
if((p = strchr(data.artist, '\n')) != NULL)
{
*p = '\0';
}
for(temp = 0;temp<data.numberTracks;temp++)
{
fscanf(fp,"%[^|]|",data.SongList[temp].SongTitle);
}
AddToList(root, data);
};
}
fclose(fp);
the text does get saved to file, but it includes extra information, when i did a watch on the program and stepped through it, i noticed that the 'feof' doesn't stop at the end, it wants to loop that extra one time, therefore causing extra information to be included
the text file structure is as so:
1----2-----3---4----5-----6-----7---8
char|char|int|char|char|char|int|char
numbers one and two are the artist and title of the cd, number 3 is the number of tracks, 4 is the tracks whose size will depend on 3, 5,6,7,8 is the next cd
all i want is for the loop to stop at the end of the list and not continue any further
please help
thanx