本帖最后由 邀请码 于 2016-2-25 20:35 编辑
车辆管理系统
[mw_shl_code=cpp,true]
#include <stdio.h>
#include <string.h>
#include <time.h>
struct tagChe
{
int time;
char name[20];
};
int main(int argc,char* argv[])
{
int i;
if(argc!=3)
{
printf("%s:error!\n",argv[0]);
return 0;
}
if(strcmp(argv[1],"-c")==0)//有车进来
{
int t;
FILE* fp = fopen("data.txt","a+");
fprintf(fp,"%d %s\n",t=time(NULL),argv[2]);
printf("录入成功!时间: %d。牌照:%s\n",t,argv[2]);
fclose(fp);
return 0;
}
else if(strcmp(argv[1],"-l")==0)//有车出去
{
struct tagChe che[1000];
memset(che,0,sizeof(che));
FILE* fp = fopen("data.txt","r");
int I=-1;
int len;
for(i=1;;i++)
{
if(fscanf(fp,"%d%s",&che.time,che.name)!=2)
{
len=i;
break;
}
if(strcmp(che.name,argv[2])==0)
I=i;
}
if(I!=-1)//找到了
{
int ct=time(NULL);
printf("当前时间:%d 入库时间:%d 停车时间:%d 价格:%d 车牌照:%s \n",ct,che[I].time,ct-che[I].time,(ct-che[I].time)/3600*5,che[I].name);
fclose(fp);
fp = fopen("data.txt","w");
for(i=1;i<=len-1;i++)
{
if(i==I)continue;
fprintf(fp,"%d %s\n",che.time,che.name);
}
fclose(fp);
return 0;
}
else//没找到
{
printf("没有找到数据!\n");
fclose(fp);
return 0;
}
}
else//输入错误
{
printf("%s:error!\n",argv[0]);
return 0;
}
return 0;
}
[/mw_shl_code]
|