Okay for an assigment I have to create a date book using a linked list, but I am having trouble getting the thing to link and display. My display loop is infinite for some reason and data entry fills my entire list with that one node's data. I am also supposed to be able to delete, save to a file, restore from finle and clear the list. However, the list doesn't work. Someone give me a hand please.
Code:
#include <iostream.h>
#include <string.h>
struct object
{
int date;
int time;
string description;
object *next;
};
object *front;
void newEntry(object *newEvent);
void displayList();
using namespace std;
main()
{
object *event;
object *temp;
event=new object;
front=0;
int i=0;
int j=0;
while(i==0)
{
newEntry(event);
if(j==2)
displayList();
j++;
}
}
void newEntry(object *newEvent)
{
cout<<"Date: ";
cin>>newEvent->date;
cout<<"Time: ";
cin>>newEvent->time;
cout<<"Description: ";
getline(cin, newEvent->description);
newEvent->next=front;
front=newEvent;
newEvent=0;
}
void displayList()
{
object *temp;
temp=front;
while(temp != 0)
{
cout<<temp->date;
cout<<temp->time<<"\n";
cout<<temp->description<<"\n";
system("pause");
}
}