关于C程序中结构体的简单再问,谢谢大家!

来源:百度知道 编辑:UC知道 时间:2024/06/02 05:32:21
程序如下:
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{long num;
float score;
struct student *next;
};
int n;
struct student *creat(void)
{struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)nalloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}
void print(struct student *head)
{struct student *p;
printf("\nNow,These %d records are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%ld%5.1f\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}
struct student *del(struct student *head,long nu

首先第一点是else和printf语句连带了,下面的输出部分第二节没有取址号& ;二点是根本不需要end这条qbasic中的语句体,在c中只要"; "就可以表示结束:

太长了,一般是自己在脑子里先运行一边。然后在在电脑里运行。看是在多少句卡住了。然后在改。

return(&head);