for a school compsci assignment my class was asked to make a simple database program to keep track of a user's mp3 collection. the program must be able to read a list of mp3s from a file, save the list to a file, sort the list, add songs, remove songs, and whatever other things i can come up with. i decided to use linked lists and for the most part it was working fine. my problem however, comes when reading and writing to a file.
when trying to load a file, it gets stuck inside the loop (never reaching the iFile.eof() in order to exit). i can't figure out what's wrong.
i've attached the entire source so you can try to understand what's going on, but the loadList() function is the focus of my problem:
and here's the text file to load:Code:void loadList() { char file [40]; char junk [40]; newList(); // to delete any songs already loaded cout << "Input the filename of the playlist to be loaded:\n"; cin.getline (file, 40,'\n'); ifstream iFile (file); if (!iFile.is_open()) { cout << "You wreckless fool of a Took! That file doesn't exist!\n"; return; } root = new mp3t; position = root; position->prev = NULL; position->next = NULL; iFile.getline (position->title,40, '\n'); iFile.getline (position->artist, 40, '\n'); iFile.getline (position->filename, 40, '\n'); iFile >> position->filesize; iFile >> position->length; iFile >> position->year; iFile.getline (junk, 40, '\n'); while (!iFile.eof()) { position->next = new mp3t; position->next->prev = position; position = position->next; position->next = NULL; iFile.getline (junk, 40, '\n'); iFile.getline (position->title, 40, '\n'); iFile.getline (position->artist, 40, '\n'); iFile.getline (position->filename, 40, '\n'); iFile >> position->filesize; iFile >> position->length; iFile >> position->year; iFile.getline (junk, 40, '\n'); } iFile.close(); }
blah blah blah!
nobody cares
its a file.mp3
213465
100001
1999
blah blah blah!2
nobody cares2
its a file.mp32
213465212
100001212
1999212
blah blah blah!3
nobody cares3
its a file.mp33
213465213
100001213
1999213
any help would be greatly appreciated, thanks.
PS, you can just ignore the humour, it's pointless right now, but once the program works i know the teacher will like it (besides, i can't help it)



LinkBack URL
About LinkBacks



, but at least it works now.