#include
#include
struct student{
char name[20];
int score;
struct student next;
};
typedef struct student STU;
void print(STU *tail,STU *p_cur);
STU display(STU *p_cur);
void pfree(STU *tmp,STU *head);
int main()
{
STU *head,*tail,*p_cur,*tmp;
int i;
i=0;
head=(STU)malloc(sizeof(STU));
printf("please input the name");
scanf("%s",head->name);
printf("please input the score");
scanf("%d",&head->score);
head->next=NULL;
head->next=p_cur;
p_cur=head;
for(i=0;i {
print(tail,p_cur);
}
printf("display");
p_cur=head;
display(p_cur);
pfree(tmp,head);
return 0;
}
void print(STU *tail,STU *p_cur)
{
tail=(STU*)malloc(sizeof(STU));
printf("please input the name");
scanf("%s",tail->name);
printf("please input the score");
scanf("%d",&tail->score);
tail->next=NULL;
p_cur->next=tail;
tail=p_cur;
}
STU display(STU *p_cur)
{
for(p_cur!=NULL)
{
printf("the name: %s,the score : %d",p_cur->name,p_cur->score);
p_cur=p_cur->next;
}
return *p_cur;
}
void pfree(STU *tmp,STU *head)
{
while(head->next!=NULL)
{
tmp=head->next;
head->next=tmp->next;
free(tmp);
}
free(head);
}
这个程序有毛病求解答