I have a data file, which reads the data in to a linked list using a for loop;
Code:
ifstream datafile ("max.txt", ios :: in);
if (!datafile)
{
cout<<"Unable to open the file"<<endl<<endl;
}
else
{
datafile>>currentp->name;
datafile>>currentp->itemnumber;
datafile>>currentp->price;
for(int i=0; i<2; i++)
{
currentp->nextp = new furniture;
currentp = currentp->nextp;
datafile>>currentp->name;
datafile>>currentp->itemnumber;
datafile>>currentp->price;
}
when i try to use a function to print out the data in the linked list the program crashes.
Code:
void printList(furniture* startp)
{
furniture* currentp;
currentp = startp;
while(currentp ->nextp !=NULL)
{
cout << currentp->name<<"\t";
cout << currentp->itemnumber<<"\t";
cout << currentp->price<<endl;
currentp = currentp->nextp;
}
cout << endl;
}
any ideas.