问题遇到的现象和发生背景
在输出时没有集体的员工信息
问题相关代码,请勿粘贴截图 {
char position[20];
char number[20];
char name[20];
char level[20];
int salary;
}ElemType;
typedef struct
{
ElemType data[Maxsize];
int length;
}SqList;
void CreateList(SqList*&L,ElemType a[],int n)
{
int i=0,k=0;
L=(SqList*)malloc(sizeof(SqList));
while(i<n)
{
L->data[k]=a[i];
k++;
i++;
}
L->length=k;
}
int ListEmpty(SqList*L)
{
return(L->length==0);
}
void DispList(SqList*L)
{
int i;
if(ListEmpty(L))
{
return;
}
printf("员工信息为:\n");
for(i=0;i<L->length;i++)
{
printf("%s %s %s %s %s %d",L->data[i].position,L->data[i].number,L->data[i].name,L->data[i].level,L->data[i].salary);
printf("\n");
}
}
int main()
{
SqList*L;
int k;
struct stuff a[5]=
{
{"董事长","WL001","表姐","A5",10000},
{"总经理","WL002","凌祯","A4",9000},
{"董事长秘书","WL003","邹新文","A3",8500},
{"秘书","WL004","李明","B6",7000},
{"秘书","WL005","翁国栋","B1",5000}
};
CreateList(L,a,5);
DispList(L);
return 0;
}
运行结果及报错内容
(输出的内容只有这样的)
员工信息为: