运行出了问题?不知道为什么
#include<stdio.h>#include<stdlib.h>
#include<malloc.h>
#define LIST_INIT_SIZE 30;
struct EmployeeCode{
char name[9];
char number[9];
char postion[9];
struct EmployeeCode *next;
};
typedef struct EmployeeCode Employee;
//Employee
typedef struct {
Employee *elem;
int length;
int listsize;
}list;//list
//定义函数
bool InitList(list &L)
{
L.elem=(Employee *)malloc(sizeof(Employee));
if(!L.elem)
return 0;
L.length=0;
L.listsize=LIST_INIT_SIZE;
return 1;
}//InitList
bool ListInsert(list &L,Employee *e)
{
Employee *p=L.elem;
while(p->next!=NULL ) //运行时,总卡在这
p=p->next;
e->next=NULL;
p->next=e;
return true;
}//ListInsert
bool ListDelete(list &L,int i)
{
Employee *p=L.elem;
Employee *pi=p->next;
i-=1;
while(i-- && pi->next )
{
p=p->next;
pi=pi->next;
}
p->next=pi->next;
free(pi);
return 1;
}
bool newEmployee(list &L)
{
Employee *newm=(Employee *)malloc(sizeof(Employee)),* p;
printf("name:");
scanf("%s",&newm->name);
printf("number");
scanf("%s",&newm->number);
printf("postion");
scanf("%s",&newm->postion);
p=newm;
if(ListInsert(L,p))
{
L.length+=1;
return 1;
}
else
return 0;
}
void print(list L){
Employee *p = L.elem->next;
while(p!=NULL)
{
printf("姓名是",p->name);
printf("工号是",p->number);
printf("职位是",p->postion);
p=p->next;
}
}
int mainprint(list L)
{
int num;
printf("请选择");
printf(" 1.有职员加入 ");
printf(" 2.有职员离开 ");
printf(" 3.打印 ");
scanf("%d",&num);
switch(num)
{
case (1):
if(newEmployee( L))
return 1;
else
{
printf("error");
return 0;
}
case (2):
int i;
printf("请输入要删除的位置");
scanf("%d",&i);
if(ListDelete( L,i))
return 1;
else
printf("error");
return 0;
case (3):
print(L);
return 1;
case (4):
return 0;
}
}
int main(){
list L;
if(!InitList(L)) {
printf("init false");
return 0;
}
int judge = mainprint(L);
while(judge == 1){
judge = mainprint(L);
}
return 0;
}
运行时,总卡在红色的地方,麻烦各位前辈指教指教