求大神看看这个程序该怎么改。。
程序代码:
#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( " 6. Query\n ");
printf( " 7. Add records from a Text File\n ");
printf( " 8. Write to a Text File\n ");
printf( " 9. research records\n ");
printf( " 0. Quit\n ");
printf( " Please input the number(0~9): ");
scanf( " %d ",&num);
while(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[ 10]);
printf( " 车牌号:\t ");
scanf( " %d ",&trafList[n].car);
printf( " 开单警察:\t ");
scanf( " %s ",&trafList[n].police[ 10]);
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[ 10]);
printf( " 违章车牌\t%d\n ",trafList[i].car);
printf( " 开单警察\t%s\n ",trafList[i].police[ 10]);
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 ");
}
}
void Delete_a_record(Traffic trafList[], int i)
{
Traffic L1={ ' \0 ', 0, ' \0 ', 0, 0, 0, 0};
trafList[i]=L1;
}
int Delete(Traffic trafList[], int n, char *name)
{ int i,t,x;
for(i= 0;i<n;i++)
{
t=( int)strcmp(name,trafList[i].driver);
if(t== 0)
{
Delete_a_record(trafList,i);
x=i;
}
}
if(i==n)printf( " 查无此人!!! ");
return x;
}
void Sort_by_Name(Traffic trafList[], int n)
{
}
int Insert(Traffic trafList[], int n,Traffic *s)
{
}
int Query(Traffic trafList[], int n, char *name)
{
}
int addfromText(Traffic trafList[], int n)
{
}
void WritetoText(Traffic trafList[], int n, char *filename)
{
}
main()
{Traffic trafList[NUM];
char Tlistname[ 20],Name[ 10],c;
char *name=Name;
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[ 10]);
t=Delete(trafList,n,name);
break;
}
case( 4):;
case( 5):;
case( 6):;
case( 7):;
case( 8):;
case( 9):;
case( 0):{
printf( " 正在关闭程序......\n ");
exit( 0);
}
}
}
}
#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( " 6. Query\n ");
printf( " 7. Add records from a Text File\n ");
printf( " 8. Write to a Text File\n ");
printf( " 9. research records\n ");
printf( " 0. Quit\n ");
printf( " Please input the number(0~9): ");
scanf( " %d ",&num);
while(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[ 10]);
printf( " 车牌号:\t ");
scanf( " %d ",&trafList[n].car);
printf( " 开单警察:\t ");
scanf( " %s ",&trafList[n].police[ 10]);
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[ 10]);
printf( " 违章车牌\t%d\n ",trafList[i].car);
printf( " 开单警察\t%s\n ",trafList[i].police[ 10]);
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 ");
}
}
void Delete_a_record(Traffic trafList[], int i)
{
Traffic L1={ ' \0 ', 0, ' \0 ', 0, 0, 0, 0};
trafList[i]=L1;
}
int Delete(Traffic trafList[], int n, char *name)
{ int i,t,x;
for(i= 0;i<n;i++)
{
t=( int)strcmp(name,trafList[i].driver);
if(t== 0)
{
Delete_a_record(trafList,i);
x=i;
}
}
if(i==n)printf( " 查无此人!!! ");
return x;
}
void Sort_by_Name(Traffic trafList[], int n)
{
}
int Insert(Traffic trafList[], int n,Traffic *s)
{
}
int Query(Traffic trafList[], int n, char *name)
{
}
int addfromText(Traffic trafList[], int n)
{
}
void WritetoText(Traffic trafList[], int n, char *filename)
{
}
main()
{Traffic trafList[NUM];
char Tlistname[ 20],Name[ 10],c;
char *name=Name;
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[ 10]);
t=Delete(trafList,n,name);
break;
}
case( 4):;
case( 5):;
case( 6):;
case( 7):;
case( 8):;
case( 9):;
case( 0):{
printf( " 正在关闭程序......\n ");
exit( 0);
}
}
}
}