#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<malloc.h>
struct student
{
char name[10];
struct student *next;
};
void list(struct student *p)
{
while(1)
{
printf("%s\n", p->name);
if(p->next != NULL)
{
p = p->next ;
}
else
{
break;
}
}
}
struct student *create()
{
struct student *head;
struct student s1 = { "11", NULL };
struct student s2 = { "11", NULL };
struct student s3 = { "22", NULL };
struct student s4 = { "33", NULL };
s1.next = & s2;
s2.next = & s3;
s3.next = & s4;
head = & s1;
return head;
}
int main()
{
struct student *p;
p = create();
list(p);
return 0;
}
为啥无法真常输出?该咋改,求帮助
简单链表疑惑,结果无法输出
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
CSDN专家-link 2021-10-14 12:32关注create函数里定义了多个局部变量,出了这个函数就被回收了。这几个学生变量要用malloc申请动态空间才行
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报