为什么输入完数据就开始不停得循环了?
#include<string.h>#include<stdio.h>
#include<malloc.h>
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define MAXSIZE 100
typedef struct workers
{ char name[15];//姓名
char department[18];//单位
char gender;//性别
unsigned int age;//年龄
unsigned long telephone;//电话
unsigned long wage;//工资
unsigned long num;//职工号
struct workers *next;
}DataType;
typedef struct
{
DataType wok[MAXSIZE];
int length;
}sequenlist;
int menu_select ()
{
int k;
printf("\n 员工管理系统\n");
printf("******************************************\n ");
printf("************1.员工信息表建立**************\n ");
printf("************2.插入员工信息****************\n ");
printf("************3.修改员工信息****************\n ");
printf("************4.查询员工信息****************\n ");
printf("************5.员工信息排序****************\n ");
printf("************6.员工信息删除****************\n ");
printf("************0.退出************************\n ");
printf("------------------------------------------\n ");
printf("请选择0-5:\n");
for(;;)
{
scanf("%d",&k);
if(k<0||k>5)
printf("选择错误,重选1-5\n");
else
break;
}
return k;
}// 菜单
void CreateList (sequenlist *L)
{
int i;
int n;
printf("请输入员工数量");
fflush(stdin);
scanf("%d",&n);
printf("请输入这%d位员工的信息\n",n);
printf("----------------------------------------\n");
for(i=1;i<=n;i++)
{ printf("第%d个职工:",i);
printf("\n姓名 单位 性别 年龄 电话 工资 职工号 \n");
scanf("%c%c%c%d%s%d%s",&L->wok[i].name,&L->wok[i].department,&L->wok[i].gender,&L->wok[i].age,&L->wok[i].telephone,&L->wok[i].wage,&L->wok[i].num);
printf("***************************************\n");
}
L->length=n;
}// 表的建立
int FindListbynum (sequenlist *L)
{ int i=0;
char name[15];
printf("请输入要查询职工的姓名\n");
scanf("%s,name");
for(i=0;i<=L->length;i++)
{
if(strcmp(L->wok[i].name,name)==0)
return i;
}
return -1;
}
void del(sequenlist *L)
{
int i,j;
i=FindListbynum (L);
if(i==-1)
{printf("信息输入有误\n");
return;
}
for(j=i;j<=L->length;j++)
{
L->wok[j].age= L->wok[j+1].age;
}
}
int main ()
{
sequenlist *L;
DataType *workers;
int i;
L=(sequenlist*)malloc(LIST_INIT_SIZE*sizeof(sequenlist));
while (1)
{
switch (menu_select())
{case 1:
printf("********************************\n");
printf("********职工线性表的建立********\n");
printf("********************************\n");
CreateList (L);
break;
case 4:
printf("********************************\n");
printf("**********职工信息查找**********\n");
printf("********************************\n");
FindListbynum (L);
break;
case 0:
printf("再见!\n");
}
}
return 0;
}