简单的数据结构问题

#include "stdio.h"
#include "string.h"
#define maxsize 30
typedef struct
{
int num;
char name[8];
float score;
}elemtype;
typedef struct
{
elemtype elem[maxsize];
int length;
}seqlist;
void create_seqlist(seqlist *L)
{
int i,n,num;
char ss[8];
float score;
printf("please input lise length:\n");
scanf("%d",&n);
L->length=n;
for(i=1;i<=n;i++)
{
printf("qing shu ri num,name,score:\n");
scanf("%d",&num);
getchar();gets(ss);
scanf("%f",&score);
L->elem[i].num=num;
strcpy(L->elem[i].name,ss);
L->elem[i].score=score;
}
}

void print_seqlist(seqlist *L)
{
int i;
printf("the list is:\n");
for(i=1;i<=L->length;i++)
printf("num=%d,name=%s,score=%f\n",L->elem[i].num,L->elem[i].name,L->elem[i].score);
}
void main()
{
seqlist *L;
create_seqlist(L);
print_seqlist(L);
}
哪里出问题了,执行之后有问题 ,不晓得哪里出错了,大伙帮个忙啊 解决

你好!!!
#include "stdio.h"
#include "string.h"
#include<malloc.h>
#define maxsize 30

typedef struct
{
int num;
char name[8];
float score;
}elemtype;

typedef struct
{
elemtype elem[maxsize];
int length;
}seqlist;

void create_seqlist(seqlist *L)
{
int i,n,num;
char ss[8];
float score;
printf("please input lise length:\n");
scanf("%d",&n);
L->length=n;

for(i=1;i<=n;i++)
{
printf("qing shu ri num,name,score:\n");
scanf("%d%s%f",&num,ss,&score);//可以使用一个输入语句
getchar();

/*gets(ss);
scanf("%f",&score);
getchar();*/
L->elem[i].num=num;
strcpy(L->elem[i].name,ss);
L->elem[i].score=score;

}
}

void print_seqlist(seqlist *L)
{

int i;
printf("the list is:\n");

for(i=1;i<=L->length;i++)
printf("num=%d,name=%s,score=%f\n",L->elem[i].num,L->elem[i].name,L->elem[i].score);
}
void main()
{
seqlist *L=(seqlist*)malloc(sizeof(seqlist));//需要开辟空间
create_seqlist(L);
print_seqlist(L);
}

测试:
please input lise length:
2
qing shu ri num,name,score:
10 wang 90
qing shu ri num,name,score:
30 chen 80
the list is:
num=10,name=wang,score=90.000000
num=30,name=chen,score=80.000000
Press any key to continue
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答