上了一点课,第一次写链表,摸索着写了,但是无法输出,可以帮忙看看吗
#include
using namespace std;
struct link
{
int number;
char name[100];
char sex;
int age;
struct link *next;
};
int main()
{
struct link *head;
head=new link;
head->next=NULL;
struct link *p,*pr;
pr=new link;
head=pr;
for(int i=0;i<5;i++)
{
p=new link;
cin>>p->number;
cin>>p->name;
cin>>p->sex;
cin>>p->age;
pr=p;
pr->next=NULL;
}
while(head!=NULL)
{
cout<number<<" ";
cout<name<<" ";
cout<sex<<" ";
cout<age<<" ";
head=head->next;
cout<
上了一点课,第一次写链表,不知道哪里出了错,可以帮忙看看吗,万分感谢

head 指向了哪个记录?那个记录的 next 指向了下一个了吗? 请你在纸上画一下,就会发现问题了。