哪位高手指点一下,线性表那输出有误(刚学数据结构型)
#include<stdio.h>#include<stdlib.h>
#define list_init_size 100
#define listincrement 10
#define overflow -2
#define OK 1
#define ERROR 0
#include<malloc.h>
typedef int status;
typedef struct student
{
int num;
char name[10];
float score;
}elemtype;
typedef struct
{
elemtype *stu;
int length;
int listsize;
}sqlist;
status initlist_sq(sqlist &L) //建立空表L
{
L.stu=(elemtype *)malloc(list_init_size *sizeof(elemtype));
if(!L.stu) exit(overflow);
L.length=0;
L.listsize=list_init_size;
return OK;
}
int input(sqlist &L)
{
int n;
printf("intput n:\n");
scanf("%d",&n);
elemtype *p;
p=L.stu;
int i=1;
for(i=1;i<=n;i++)
{
printf("input the %d information:\n",i);
scanf("%d,%s,%f",&(*p).num,&(*p).name,&(*p).score);
p++;
}
L.length=n;
return OK;
}
int locateelem_sq(sqlist L,elemtype e,status(*compare)(elemtype,elemtype))
{
elemtype *p;
int i=1;
p=L.stu;
while(i<=L.length&&!(compare)(*p++,e))
i++;
if(i<=L.length) return i;
else return 0;
}
status compare(elemtype e1,elemtype e2 ) //具体的比较函数
{
if(e1.num=e2.num) return OK;
else return ERROR;
}
void print(sqlist L)
{
int i=1;
elemtype *p;
p=L.stu;
for(i=1;i<=L.length;i++)
{
printf("\n%d,%s,%f\n",(*p).num,(*p).name,(*p).score);
p++;
}
}
void main()
{
int a;
sqlist L;
elemtype *e;
initlist_sq(L);
input(L);
printf("显示输入的数据:\n");
print(L);
printf("输入定位的数据:\n");
scanf("%d,%s,%f",&(*e).num,&(*e).name,&(*e).score);
a=locateelem_sq(L,*e,compare);
printf("输入的是L中的第%d个数据\n",a);
}