qq_37130151 2017-03-22 13:32 采纳率: 100%
浏览 803
已采纳

C语言链表问题....................

#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);
}
这个程序有毛病求解答

  • 写回答

2条回答 默认 最新

  • devmiao 2017-03-22 15:25
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM