求指点哪个地方错了。。。
#include<stdio.h>#include<string.h>
#include<stdlib.h>
#define NUM 200
typedef struct
{
char driver[10];
int car;
char police[10];
int num;
int year;
int month;
int date;
}Traffic;
int my_menu()
{ int num;
system("cls");
printf("1. Input records\n");
printf("2. Display all records\n");
printf("3. Delete a record\n");
printf("4. sort\n");
printf("5. Insert a record\n");
printf("0. Quit\n");
printf("Please input the number(0~9):");
scanf("%d",&num);
if(num<0||num>9)
{
printf("输入错误,请重新输入: \n");
system("pause");
my_menu();
scanf("%d",&num);
}
return num;
}
int Input(Traffic trafList[],int n)
{ int word;
do
{
printf("Please increase the record:\n");
printf("请输入违章司机姓名、车牌号、开罚单警察、罚单号、罚单的年、月和日:\n");
printf("违章司机:\t");
scanf("%s",trafList[n].driver);
printf("车牌号:\t");
scanf("%d",&trafList[n].car);
printf("开单警察:\t");
scanf("%s",trafList[n].police);
printf("罚单号:\t");
scanf("%d",&trafList[n].num);
printf("年:\t");
scanf("%d",&trafList[n].year);
printf("月:\t");
scanf("%d",&trafList[n].month);
printf("日:\t");
scanf("%d",&trafList[n].date);
printf("\n");
n++;
printf("是否继续添加记录(Yes(1)/No(0)):");
scanf("%d",&word);
}
while(word==1);
return n;
}
void Display(Traffic trafList[],int n)
{ int i;
for(i=0;i<n;i++)
{printf("违章司机\t%s\n",trafList[i].driver);
printf("违章车牌\t%d\n",trafList[i].car);
printf("开单警察\t%s\n",trafList[i].police);
printf("罚单编号\t%d\n",trafList[i].num);
printf("年\\月\\日\t%d\\%d\\%d\n",trafList[i].year,trafList[i].month,trafList[i].date);
printf("\n\n");
while((i+1)%10==0)printf("\f");
}
}
int Delete_a_record(Traffic trafList[],int nu,int n)
{int i;
for(i=nu;i<n-1;i++)
trafList[i]=trafList[i+1];
n--;
return n;
}
int Delete(Traffic trafList[],int n,char *name)
{ int i,t,m;
m=n;
for(i=0;i<m;i++)
{
t=(int)strcmp(name,trafList[i].driver);
if(t==0)
{
m=Delete_a_record(trafList,i,m);
i--;
}
}
if(i==m&&m==n)
{
printf("查无此人!!!\n");
system("pause");
}
return m;
}
void Sort_by_Name(Traffic trafList[],int n)
{ int i,j,k;
Traffic Tr;
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
if(strcmp(trafList[i].driver,trafList[j].driver)>0)
{
Tr=trafList[i];
trafList[i]=trafList[j];
trafList[j]=Tr;
}
}
}
int Insert(Traffic trafList[],int n,Traffic s)
{ int i,j;
printf("请输入插入的违章司机姓名:\t");
scanf("%s",s.driver);
printf("车牌号:\t");
scanf("%d",&s.car);
printf("开单警察:\t");
scanf("%s",s.police);
printf("罚单号:\t");
scanf("%d",&s.num);
printf("年:\t");
scanf("%d",&s.year);
printf("月:\t");
scanf("%d",&s.month);
printf("日:\t");
scanf("%d",&s.date);
printf("\n");
for(i=0;i<n;i++)
if(strcmp(trafList[i].driver,s.driver)>0)
{
for(j=n;j>i;j++)
{
trafList[j]=trafList[j-1];
}
trafList[i]=s;
break;
}
n++;
return n;
}
main()
{FILE *fp;
Traffic trafList[NUM],s;
char Tlistname[20],Name[10],c;
char *name=Name,*filename;
int i,n=0,t;
for(i=0;;i++)
{
switch(my_menu())
{
case(1): {
n=Input(trafList,n);
break;
}
case(2): {
Display(trafList,n);
system("pause");
break;
}
case(3): {
printf("Please input the name to delete the record:");
scanf("%s",name);
n=Delete(trafList,n,name);
break;
}
case(4):Sort_by_Name(trafList,n);
break;
case(5):n=Insert(trafList,n,s);
break;
case(0):{
printf("正在关闭程序......\n");
exit(0);
}
}
}
}
这个程序Insert函数 不能按预期插入数据。。请问这是什么原因?