这是一个存储数据的结构体;也是链表结点的数据结构如下:
#include
#include
#include
#define size sizeof(struct student)
struct student {
char name[30];
int number;
float score[4];
struct student *next;
};
struct student *head;//头节点;
struct student *create()
{
struct student *ps,*pend;
head=NULL;
pend=ps;
ps=malloc(size);
printf("please input the data:name,number,englist,math,computer,polic. \n");
scanf("%s%d%f%f%f%f",ps->name,&ps->number,&ps->score[0],&ps->score[1],&ps->score[2],&ps->score[3]);
while(strcmp(ps->name,"0")!=0 && ps->number!=0 )
{
if(head==NULL)
head=ps;
else
pend->next=ps;
pend=ps;
ps=malloc(size);
printf("please input the data:\n");
scanf("%s%d%f%f%f%f",ps->name,&ps->number,&ps->score[0],&ps->score[1],&ps->score[2],&ps->score[3]);
}
pend->next=NULL;
free(ps);
return head; //返回非常重要的头节点;
}