33,010
社区成员
发帖
与我相关
我的任务
分享
#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 2
#define NULL 0
typedef struct node
{
int num;
int score;
struct node *next;
}student;
student *creat_list( student *L)
{
int i;
student *p,*r;
L=(student * )malloc(sizeof(student));
L->next=NULL;
r=L;
for(i=0;i<MAXSIZE;i++)
{
p=(student *)malloc(sizeof(student));
scanf("%d,%d",&p->num,&p->score);
p->next=NULL;
r->next=p;
r=p;
}
return L;
}
void print_list(student *L)
{
student *s;
s=L->next;
while(s!= NULL) //自身不为空时,打印出来
{
printf("%d,%d\n",s->num,s->score);
//s++;
s = s->next;
}
}
void main()
{
student *L,*q;
L=NULL;
printf("输入相关数据:\n");
q=creat_list(L);
printf("相关数据为:\n");
print_list(q);
}