C语言用户已存在代码,看看这个代码有什么问题,我已经放弃了,,,找不到问题所在,,看...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

#include

#include

#include

#define LEN sizeof(struct student)

struct student

{

int num;

float score;

struct student *next;

};

int n,m;

struct student *creat()

{

struct student *p1,*p2,*head;

p2=p1=(struct student*)malloc(LEN);

scanf("%d",&p1->num);

scanf("%f",&p1->score);

head=NULL;

m=n=0;

while(p1->num)

{

n++;

m++;

if(n==1)

{

head=p1;

}

else

{

p2->next=p1;

}

p2=p1;

p1=(struct student*)malloc(LEN);

scanf("%d",&p1->num);

scanf("%f",&p1->score);

}

p2->next=NULL;

return head;

}

void print(struct student *head)

{

struct student *p;

p=head;

while(n--)

{

printf("%d\n",p->num);

printf("%f\n",p->score);

p=p->next;

}

}

struct student *del(struct student *head,int num)

{

struct student *p1,*p2;

p1=head;

while(p1->next!=NULL && num!=p1->num)

{

p2=p1;

p1=p1->next;

}

if(p1==head)

{

head=p1->next;

}

else

{

p2->next=p1->next;

}

return head;

}

struct student *add(struct student *head,int num1,float score1)

{

struct student *p1,*o3;

p1=head;

while(p1->next!=NULL)

{

p1=p1->next;

}

o3=(struct student*)malloc(LEN);

o3->num=num1;

o3->score=score1;

p1->next=o3;

o3->next=NULL;

return head;

}

void main()

{

int num,num1;

float score1;

struct student *stu,*stu1,*stu2;

stu1=creat();

print(stu1);

printf("have %d the num\n ",m);

printf("please enter the num:");

scanf("%d",&num);

stu=del(stu1,num);

print(stu);

printf("please enter the num1 and score1:");

scanf("%d",&num1);

scanf("%f",&score1);

stu2=add(stu1,num1,score1);

print(stu2);

system("pause");

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值