#include <stdio.h>
#include <stdlib.h>
struct studentinfo
{
char name[20];
char num[20];
int score[20];
struct studentinfo *next;
}
typedef struct studentinfo NODE;
NODE *create_linklist (int i);
//void insert_linklist (NODE *head,NODE *pnew,int i);
//void delete_linklist (NODE *head,int i);
void display_linklist (NODE **pstu,int num);
void free_linklist (NODE **pstu,int num);
NODE *create_linklist (int i)
{
NODE *p;
p=(NODE *)malloc (sizeof(NODE));
if (p=NULL)
return NULL;
printf("\n====input %th student's information==== \n",i+1);
printf("NO.: ");
scanf("%s",p->num);
printf("Name: ");
scanf("%s",p->name);
fflush(stdin);
for (i=0;i<3;i++)
{
printf("Score %d: ",i+1);
scanf("%d",&p->score[i]);
}
return p;
}
void free_linklist (NODE **pstu,int num)
{
int i;
for (i=0;i<num;i++)
free(pstu[i]);
free(pstu);
}
void display_linklist (NODE **pstu,int num)
{
NODE *p;
for (p=pstu->next;p!=NULL;p=p->next)
{
printf("%s",p->num);
printf("%s",p->name);
for (int j=0;j<3;j++)
printf("%d",p->score[j]);
printf("\n");
}
}
void main()
{
NODE **pstu;
int i,num;
printf("input the number of the students: ");//输入学生人数
scanf("%d",&num);
if (num<=0)
return;
pstu=(NODE **)malloc (num*sizeof(NODE *));
if (pstu==NULL)
{
printf("not enough memory!\n");
return;
}
for (i=0;i<num;i++)
{
pstu[i]=create_linklist (i);
if (pstu[i]==NULL)
{
printf("not enough memory!\n");
free_linklist (pstu,i);
}
}
}