#include <stdlib.h>
#include <string.h>
void main()
{void adm2(),build(),search(),modif(),dele();
adm2();
}
void adm2()
{ char a;
void window(),clrscr(),gotoxy();
for(;;)
{ clrscr();
gotoxy(30,8);printf("built a new user (B)");
gotoxy(30,10);printf("search car (R)");
gotoxy(30,12);printf("modif cars (J)");
gotoxy(30,14);printf("delete user (D)");
a=getch();
if(a=='b') build();
if(a=='r') search();
if(a=='j') modif();
if(a=='d') dele();
else continue;
}
}
void build()
{
FILE *p;
char number[20],seat[20],type[2],state[3];
window(10,10,80,25);
clrscr();
printf("请输入车辆牌号:");
scanf("%s",number);
printf("seat:");
scanf("%s",seat);
printf("type:");
scanf("%s",type);
printf("state:");
scanf("%s",state);
p=fopen(number,"w+");
if(p==NULL) { printf("can't build that user");getchar();adm2();}
fprintf(p,"%s",number);
fprintf(p,"%s",seat);
fprintf(p,"%s",type);
fprintf(p,"%s ",state);
printf("bulid success");
getchar();
fclose(p);
}
void search()
{
FILE *fp,*p,*f;
char type[20],c,number[20],a[5][50];
int i=0,m,k; clrscr();
printf("请输入车辆牌号:");
scanf("%s",number);
p=fopen(number,"r");
if(p==NULL) { printf("error");getchar();fclose(p);exit(0);}
fscanf(p,"%s",type);
fclose(p);
fp=fopen(type,"r");
do{ fscanf(fp,"%s",a[i++]); }while(!feof(fp));
for(k=0;k<i-1;k++) printf("\ncar %d: %s",k+1,a[k]);
fclose(fp);
f=fopen(type,"w+");
for(;;)
{
printf("\n\npress the car number that you want to search");
scanf("%d",&m);
if(m==7) { for(k=0;k<i-1;k++)
{
fprintf(f,"%s\n",a[k]);
}
fclose(f);
adm2();
}
if(m==6) remove(type);
if(m<6)
for(k=0;k<i-1;k++)
{ if(k!=m-1)
fprintf(f,"%s\n",a[k]);
}
printf("book %d has returned.",m);
printf("\ncontinue? (Y/N)");
c=getchar();
if(c=='y') continue;
if(c=='n') { fclose(f);adm2(); }
}
}
void modif()
{ FILE *f,*m,*p;
char type[20],number[20],car[5][50];
int i=0,n=0,k;
window(10,10,80,25);clrscr();
printf("please input the user's number:");
scanf("%s",number);
m=fopen(number,"r");
if(m==NULL) { printf("user no exit"); getchar();fclose(m);adm2();}
fscanf(m,"%s",type);
fclose(m);
p=fopen(type,"r");
if(p==NULL);
else
{ while(!feof(p))
{
fscanf(p,"%s",car[i]);
i++;
}
i--;
for(k=0;k<i;k++) printf("\ncar %d :%s",k+1,car[k]);
}
fclose(p);
f=fopen(number,"w");
printf("\nhow many car do you want to borrow?:");
do{printf("\ninput:");scanf("%d",&n); }while(i+n>=6);
for(k=i;k<i+n;k++)
{ printf("\ncar %d :",k+1);
scanf("%s",car[k]);
}
for(k=0;k<i+n;k++) fprintf(f,"%s\n",car[k]);
fputc('\0',f);
printf("success");
fclose(f);
}
void dele()
{ FILE *fp,*f;
char c,b[5][50],number[20],a[4][20];
int i=0,j=0,k;
window(10,10,80,25);clrscr();
printf("请输入车辆牌号:");
scanf("%s",number);
fp=fopen(number,"r");
if(fp==NULL) { printf("\nuser isn't exit");getchar(); fclose(fp);adm2();}
else while(!feof(fp))
{ fscanf(fp,"%s",a[i++]);}
printf("\ntype: %s",a[0]);
printf("\nnumber: %s",a[1]);
printf("\nseat: %s",a[2]);
printf("\nstate: %s",a[3]);
f=fopen(a[0],"r");
if(f==NULL);
else {
while(!feof(f))
{ fscanf(f,"%s",b[j++]);}
for(k=0;k<j-1;k++) printf("\ncar %d: %s",k+1,b[k]);
}
printf("\nDo you want to delete? (Y/N): ");
c=getchar();
fclose(fp);
fclose(f);
if(c=='y') { remove(number);remove(a[0]);printf("\nsuccess");getchar();adm2();}
if(c=='n') adm2();
}
实在急用 没分给了 不好意思