#include "Stdio.h"
#include "Conio.h"
struct carplace { /*这是一个停车位*/
int car_id;
int floor;
int position;
int time;
int n;
}a[2][6]={234,1,1,25,1,356,1,2,15,1,478,1,3,10,1,899,1,4, 5,1};/*一个2层 每层有6位的停车场;初始化了4个位置*/
struct carplace *p=a;
FILE *pf;
if((pf=fopen("D:\\lianlian\\car","wt+"))==0){ /*这句有问题,编译时说:说明性语法错误*/
printf("can't open file strike any key exit!");
getch();
exit(1);
}
fwrite (p,sizeof(struct carplace),4,pf); /*把初始化的4个车位得数据写进文件*/
int addcar() /*停车*/
{int i=0;
int j;
printf("please input a car_id\n");
for(i=0;i<2;i++){
for(j=0;j<6;j++){
if ((a[i][j].n)!=1){
scanf("%d",a[i][j].car_id);
a[i][j].n =1;
a[i][j].floor = i+1 ;
a[i][j].position = j+1 ;
printf("the car is in floor%d,position%d\n",a[i][j].floor ,a[i][j].position);
if((pf = fopen("D:\lianlian\car","at+"))==0){
printf("can't open file strike any key exit2!") ;
getch();
exit(1);
}
fscanf(pf,"%d%d%d%d%d",&a[i][j].car_id,&a[i][j].floor,&a[i][j].position, &a[i][j].n);
return 0 ;
}
}
}
}
main()
{
int k ;
int a = addcar();
if (a==0) /*如果有车停进,把其余车俩的5存车时间加5*/
{
printf("the car is placed in\n");
for (k=0;k<12;k++,p++)
{
if (p->n == 1 )
p->time +=5;
fscanf(pf,"%d", p->time);
}
}
rewind (pf);
getch();
}
[此贴子已经被作者于2007-7-21 20:27:54编辑过]