Your problems start in this section:
Code:
for(int start=0;start<amount;start++)
{
newnode=(node*)malloc(sizeof(node));
if(newnode==NULL)
break;
if(!initialized)
{
top->next=newnode;
initialized=true;
}
newnode->next=NULL;
cout<<'\n'<<"Input your name >";
cin>>newnode->name;
cout<<'\n'<<"Input your age >";
cin>>newnode->age;
}
After you have entered one name/age, the newnode pointer is reused in the next iteration of the loop, without first storing the address in the list. It'll work once because your are doing this once:
>top->next=newnode;
Also, the way you do it, leaves an empty node at the top of the list.
Have a look at this version:
Code:
node *tmp;
node *top = NULL;
node *newnode;
int amount;
cout << "How many people to be stored >";
cin >> amount;
for (int start = 0; start < amount; start++)
{
newnode = (node *) malloc(sizeof(node));
if (newnode == NULL) break;
newnode->next = NULL;
cout << '\n' << "Input your name >";
cin >> newnode->name;
cout << '\n' << "Input your age >";
cin >> newnode->age;
if (top == NULL)
{ /* first item in list */
top = newnode;
tmp = newnode;
}
else
{ /* add to end of the list */
tmp->next = newnode;
tmp = newnode;
}
}