I'm having a little trouble reading a file into a linked list (which I'm just learning). The code I have is:
Code:
struct stock
{
char isbnChar[10],
bookNoChar[10],
borrowedFromDate[3],
loanLengthChar[3],
currentBorrowerNo[5],
lastBorrowerNo[5],
status[2];
struct stock * next;
int j;
};
stock *root = NULL;
stock *curr = NULL;
ifstream IssueBook("stock.txt", ios::in);
if (!IssueBook)
cerr << "File Ccould not be opened" << endl;
do
{
IssueBook.getline(curr->bookNoChar, 5, ',');
IssueBook.getline(curr->isbnChar, 10, ',');
IssueBook.getline(curr->borrowedFromDate, 3, ',');
IssueBook.getline(curr->loanLengthChar, 3, ',');
IssueBook.getline(curr->lastBorrowerNo, 3, ',');
IssueBook.getline(curr->currentBorrowerNo, 3, ',');
IssueBook.getline(curr->status, 2, '\n');
if (strcmp(curr->bookNoChar,bookNumChar))
strcpy(curr->status, "O");
curr->next = new stock;
curr = curr->next;
}
while( !IssueBook.eof() );
IssueBook.close();
It doesn't like IssueBook.getline(curr->bookNoChar, 5, ','); and crashes straight away.
The code should read comma sepparated values from a file into the list and change one value (in the if statement). Then I'll traverse the list putting the values back into the file with the updated one ammended.