#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);
}
这个程序有毛病求解答
C语言链表问题....................
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
悬赏问题
- ¥15 vscode的问题提问
- ¥50 切换TabTip键盘的输入法
- ¥15 可否在不同线程中调用封装数据库操作的类
- ¥15 微带串馈天线阵列每个阵元宽度计算
- ¥15 keil的map文件中Image component sizes各项意思
- ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
- ¥15 划分vlan后,链路不通了?
- ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
- ¥15 Vue3 大型图片数据拖动排序
- ¥15 Centos / PETGEM