The gist of my problem is that I am reading a file with fields separated by #'s except for the end of the line. When I look at the print statements for the fields that I am reading into a book struct (that uses a for loop to go through the entire data file/list of books (theoretically)), they all have the same value. For example, there are 200 of the exact same id followed by 200 of the exact same title instead of reading farther down on the data file.
The exact code is:
void loadTable(book table[], int size){
for (int i = 0; i < size; i++){
book newBook;
ifstream ifs("inventory.txt");
string bit;
getline(ifs, bit, '#');
newBook.bookId = atoi(bit.c_str());
cout << "BookID: " << newBook.bookId;
getline(ifs, bit, '#');
newBook.title = bit;
cout << "Title: " << newBook.title;
getline(ifs, bit, '#');
newBook.author = bit;
getline(ifs, bit, '#');
newBook.cost = atof(bit.c_str());
getline(ifs, bit, '#');
newBook.price = atof(bit.c_str());
getline(ifs, bit);
newBook.quantity = atoi(bit.c_str());
loadBook(table, newBook, size);
}
}
And the exact result:
tiesBookID: 116807Title: A Tale of Two CitiesBookID: 116807Title: A Tale of Two
CitiesBookID: 116807Title: A Tale of Two CitiesBookID: 116807Title: A Tale of Tw
o CitiesBookID: 116807Title: A Tale of Two CitiesBookID: 116807Title: A Tale of
Two CitiesBookID: 116807Title: A Tale of Two CitiesBookID: 116807Title: A Tale o
f Two CitiesBookID: 116807Title: A Tale of Two CitiesBookID: 116807Title: A Tale
of Two CitiesBookID: 116807Title: A Tale of Two CitiesBookID: 116807Title: A Ta
...