一个初学链表的人,不知道这个链表程序哪里出问题了,能运行,但是结果有大问题,请教大佬看一看,下面是程序,(程序的运行结果应该和最后面的图片差不多)

#include<stdio.h>

#include<stdlib.h>

# define NULL 0

struct student

{

int num;

char name[20];

struct student *next;

};

struct student *create()

{

struct student *head,*p,*last;

int num;

printf("请输入学号:");

scanf("%d",&num) ;

if (num==0)

head=NULL;

else

{p=(struct student*)malloc(sizeof(struct student));

head=p;

do

{

printf("请输入学生姓名:");

scanf("%s",p->name);

p->num=num;

p->next=NULL;

printf("请输入学号:");

scanf("%d",&num) ;

if(num!=0)

{p=(struct student*)malloc(sizeof(struct student));

last=head;

while(last)

{

last=last->next;

}

last->next=p;

}

}

while(num!=0);

}

return head;

}

void print(struct student *head)

{

struct student *p;

p=head;

while(p)

{

printf("%d,%s",p->num ,p->next);

p=p->next;

}

}

int main()

{

struct student *head;

head=create();

print(head);

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值