栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

A simple C program

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

A simple C program

#include//printf()scanf()fflush(),fread(),fwrite()fopen()fclose(),fprintf(),fscanf(),
#include//strcpy()memcpy()
#include//time(),
#include//system(),srand(),random(),
#include//Sleep(),


struct customer_details{//create a struct
char name[20];
char code[20];
char university_ID[20];
char phone_number[20];
float account_balance;
char status[9];
char entry[9];};

struct unit_price{
float car;
float e_no_recharge;
float e_recharge;};


void login();
void create();	  	  	  	  
void view(); 	  	  	  	  

//some switch case
void customer();//cotains custmenu(),view(),create(),
void admin();//contain adminmenu(),change(),park(),
void worker();//contain workermenu(),money(),
void allbike();
void allcar();

//some menus
void welcomemenu();
void adminmenu();
void workermenu();
void custmenu();
void allbikemenu();
void allcarmenu();

void change();//change customer's account for admin
void unit();//to set the prameter of parking for admin
void cheakcar();// View current car-park occupation and number of free spaces
void record();//Record the entry of a registered customer
void open_record();
void carpark();//Allocate a randomly chosen parking space to each car as it enters
void free_carpark();// Free a previously allocated slot
void bikepark();
void free_bikepark();
void chargepark();
void free_chargepark();

void carmoney();//to get money for car in workermenu
void bikemoney();//to get money for e-bike in workermenu
void charge();// Charge the leaving customer accordingly


int main()
{
  int option1;


    while(1)
{
       system("cls");
       welcomemenu();
while (scanf("%d", &option1) != 1 && (option1<1 || option1>4))		
			{
			printf("Invalid entrynn");
			Sleep(2000);
			fflush(stdin);
			}
        switch(option1)
        {
        case 1:customer();
          break;
        case 2:admin();
          break;
        case 3:worker();
         break;
        case 4:printf("tGood bye.n");
                exit(0);
        default:
         printf("your input is wrong,please input the number between 1 and 4n");
         Sleep(2000);
        }

    }

    return 0;

}




void customer()
{
        fflush(stdin);
        system("cls");
        int customer_ch=0;

        custmenu();
        while (scanf("%d", &customer_ch) != 1 && (customer_ch<1 || customer_ch>3))		
			{
			printf("Invalid entrynn");
			Sleep(2000);
			fflush(stdin);
			}

        switch(customer_ch)
        {
            case 1:create();
            break;
            case 2:view();
            break;
            case 3:return;

            default:
              printf("your input is wrong,please input the number between 1 and 3n");
              Sleep(2000);
        }
}


void admin()
{
          fflush(stdin);
          login();
          system("cls");

          int admin_ch;

          adminmenu();
        while (scanf("%d", &admin_ch) != 1 && (admin_ch<1 || admin_ch>3))		
			{
			printf("Invalid entrynn");
			Sleep(2000);
			fflush(stdin);
			}

          switch(admin_ch)
          {

              case 1:change();
              break;
              case 2:unit();
              break;
              case 3:return;
              default:
              printf("your input is wrong,please input the number between 1 and 3n");
              Sleep(2000);

          }
}

void worker()
{
   fflush(stdin);
   login();
   system("cls");

   int worker_ch=0;

   workermenu();
        while (scanf("%d", &worker_ch) != 1 && (worker_ch<1 || worker_ch>6))		
			{
			printf("Invalid entrynn");
			Sleep(2000);
			fflush(stdin);
			}

   switch(worker_ch)
    {
        case 1:allcar();
        break;
        case 2:allbike();
        break;
        case 3:charge();
        break;
        case 4:record();
        break;
        case 5:open_record();
        break;
        case 6:
            return;

        default:
              printf("your input is wrong,please input the number between 1 and 6n");
              Sleep(2000);
    }
}

void allcar()
{
    int all=0;
    system("cls");
    allcarmenu();

    while (scanf("%d", &all) != 1 && (all<1 || all>5))		
			{
			printf("Invalid entrynn");
			Sleep(2000);
			fflush(stdin);
			}
    switch(all)
    {
        case 1:carmoney();
        break;
        case 2:carpark();
        break;
        case 3:cheakcar();
        break;
        case 4:free_carpark();
        break;
        case 5:return;
        default:
            printf("your input is wrong,please input the number between 1 and 5n");
              Sleep(2000);

    }
}

void allbike()
{
    int all=0;
    system("cls");
    allbikemenu();

    while(scanf("%d",&all)!=1&&(all<1||all>6))
        {
			printf("Invalid entrynn");
			Sleep(2000);
			fflush(stdin);
			}
    switch(all)
    {
        case 1:bikemoney();
        break;
        case 2:bikepark();
        break;
        case 3:chargepark();
        break;
        case 4:free_bikepark();
        break;
        case 5:free_chargepark();
        break;
        case 6:break;
        default:
            printf("your input is wrong,please input the number between 1 and 6n");
              Sleep(2000);
    }
}

void login()
{
    char *zhanghu="0101";
    char code[32];
    int m=1;
    while(m==1)
    {

        printf("please enter the password:");
        scanf("%s",code);
        printf("n");
        if(!strcmp(zhanghu,code))
        {
            printf("the password is right,please waitingn");
            m=0;
            Sleep(2000);
        }
        else
        {
            printf("the password is wrong, please enter againn");
        }
    }
    return;
}


void welcomemenu()
{
    printf("welcome to Parking Management Systemn");
    printf("please choose your identityn");
    printf("The input should be number ,others are illegaln");
    printf("t1.customern");
    printf("t2.adminn");
    printf("t3.workern");
    printf("t4.quitn");
}

void adminmenu()
{
    printf("welcome to Parking Management System's admin menun");
    printf("please make your choicen");
    printf("The input should be number ,others are illegaln");
    printf("t1.change the accountn");
    printf("t2.set the parking parametern");
    printf("t3.Back to previous pagen");
}

void custmenu()
{
    printf("welcome to Parking Management Systemn");
    printf("please make your choicen");
    printf("The input should be number ,others are illegaln");
    printf("t1.create a new accountn");
    printf("t2.view the accountn");
    printf("t3.Back to previous pagen");
}

void workermenu()
{
    printf("welcome to Parking Management Systemn");
    printf("please make your choicen");
    printf("The input should be number ,others are illegaln");
    printf("t1.operation about the car n");
    printf("t2.operations for an e-biken");
    printf("t3.Charge the leaving customer accordinglyn");
    printf("t4.Record the entry of a registered customern");
    printf("t5.Look through the information recordedn");
    printf("t6.Back to previous pagen");

}

void allbikemenu()
{
    printf("welcome to Parking Management Systemn");
    printf("please make your choicen");
    printf("The input should be number ,others are illegaln");
    printf("t1.Calculate the money for the e-biken");
    printf("t2.Allocate a randomly chosen parking space to each e-bike without charge as it entersn");
    printf("t3.Allocate a randomly chosen parking space to each e-bike with charge as it entersn");
    printf("t4.Free a previously allocated slot to each e-bike without chargen");
    printf("t5.Free a previously allocated slot to each e-bike with chargen");
    printf("t6.Back to main screenn");
}

void allcarmenu()
{
    printf("welcome to Parking Management Systemn");
    printf("please make your choicen");
    printf("The input should be number ,others are illegaln");
    printf("t1.Calculate the money for the e-biken");
    printf("t2.Allocate a randomly chosen parking space to the carn");
    printf("t3.View current car-park occupation and number of free spaces.n");
    printf("t4.Free a previously allocated slotn");
    printf("t5.Back to main screenn");

}

void change()//change customer's account for admin
{
  fflush(stdin);
  FILE*fptr;
  struct customer_details customer;
  char filename[25]="";
  char ID_number[20]="";
  char pnumber[20]="";
  float balance=0;
  char idenity[9]="";
  char codevv[20]="";

  printf("Please input the account namen");
  while (fgets(filename,19,stdin) == NULL)//to cheak whether we can input filename or not
		{
		fflush(stdin);
		printf("Something went wrong with the input, please try again:nnt");
		}
  filename[strlen(filename)-1]='';

  fflush(stdin);

  while((fptr=fopen(filename,"w"))==NULL)//to cheak whether we can write the file or not
  {
      printf("Cannot changen");
  }

  fread(&customer,sizeof(struct customer_details),1,fptr);

  printf("Please input your passwordn");
   while(scanf("%s",codevv)==0)
    {
        fflush(stdin);
		printf("Please try again and make sure the number has less than 19 digits");
    }
    strcpy(customer.code,codevv);


  printf("Please input your ID numbern");
    while(scanf("%s",ID_number)==0)
    {
        fflush(stdin);
		printf("Please try again and make sure the number has less than 19 digits");
    }
    strcpy(customer.university_ID,ID_number);

    printf("Please input the phone numbern");
    while(scanf("%s",pnumber)==0)
    {
        fflush(stdin);
		printf("Please try again and make sure the number has less than 19 digits");
    }
    strcpy(customer.phone_number,pnumber);

    printf("Please input the balancen");
    while(scanf("%f",&balance)==0)
    {
        fflush(stdin);
		printf("Please try again and make sure the number has less than 8 digits");
    }
    customer.account_balance=balance;

    printf("Please input the statusn");
    while(scanf("%s",idenity)==0)
    {
        fflush(stdin);
		printf("Please try again and make sure the number has less than 8 digits");
    }
    strcpy(customer.status,idenity);

	fflush(stdin);
    fclose(fptr);

	
	fptr = fopen(filename, "wb+");

	if (fptr == NULL) 		
		{
		printf("nnThere was a problem opening the file, please restart the programnn");
		Sleep(2000);
		exit(0);
		}
	else			
		fwrite(&customer, sizeof(customer), 1, fptr);

	fclose(fptr); 		


}

void record()
{
    fflush(stdin);
    char filename[20]="";
    char input[9]="";
    FILE*fptr;
    struct customer_details account;


    printf("Please enter customer's name:n");
    while (fgets(filename,19,stdin) == NULL)
	{
		fflush(stdin);
		printf("Something went wrong with the input, please try again:nnt");
	}

	filename[strlen(filename)-1]='';
	fflush(stdin);

    while((fptr=fopen(filename,"rb"))==NULL)
	{
		printf("This account does not exist or cannot open itn");
		return;
	}

    fread(&account,sizeof(struct customer_details),1,fptr);
    fclose(fptr);


    if((fptr=fopen("filename","wb"))==NULL)
       {
           printf("Cannot open the filen");
       }
    printf("Please input yes or not to respresent the entryn");
    fflush(stdin);
    while(scanf("%[^n]",input)==0)//when face the 'n',stop input//
        {
            printf("Your input is wrong, please try againn");
        }

    strcpy(account.entry,input);
    printf("You have recorded the entryn");
    Sleep(2000);

    fwrite(&account,sizeof(struct customer_details),1,fptr);
    fclose(fptr);
    return;
}

void open_record()
{
    fflush(stdin);
    char filename[20]="";
    FILE*fptr;
    struct customer_details account;
    char *judge="";


    printf("Please enter customer's name:n");
    while (fgets(filename,19,stdin) == NULL)
	{
		fflush(stdin);
		printf("Something went wrong with the input, please try again:nnt");
	}

	filename[strlen(filename)-1]='';
	fflush(stdin);

    while((fptr=fopen(filename,"rb"))==NULL)
	{
		printf("This account does not exist or cannot open itn");
		return;
	}

    fread(&account,sizeof(struct customer_details),1,fptr);
    fclose(fptr);

    strcpy(judge,"yes");
    if(strcmp(judge,account.entry)==0)
    {
        printf("This customer has parkedn");
    }
    else
    {
        printf("This customer has not parkedn");
    }


}

void unit()//to set the prameter of parking for admin
{
  fflush(stdin);
  FILE*fptr;

  struct unit_price price;

  while((fptr=fopen("unit_price.txt","wb"))==NULL)//to change the unit price
  {
      printf("Cannot change the unit price");
      exit(0);
  }

  printf("Please input the unit price of car:n");
  scanf("%f",&price.car);

  fflush(stdin);//avoid n in buffer
  printf("Please input the unit price of e-bike with no recharge:n");
  scanf("%f",&price.e_no_recharge);

  fflush(stdin);//avoid n in buffer
  printf("Please input the unit price of e-bike with recharge:n");
  scanf("%f",&price.e_recharge);

  fwrite(&price,sizeof(struct unit_price),1,fptr);

  fclose(fptr);
  return;
}

void carmoney()//to get money for car in workermenu
{
    FILE*fptr;
    int dt=0;
    struct unit_price price;
    price.car=0;

     while((fptr=fopen("unit_price.txt","rb"))==NULL)//to change the unit price
  {
      printf("Cannot change the unit price");
      exit(0);
  }

    printf("Please input the stopping time(s):");
    scanf("%d",&dt);
    fread(&price,sizeof(struct unit_price),1, fptr);
    printf("total money is %fn",dt*price.car);
    Sleep(2000);

    return;

}

void bikemoney()//to get money for e-bike in workermenu
{
    int option=0;
    FILE*fptr;
    struct unit_price bike;
    bike.e_no_recharge=0;
    bike.e_recharge=0;
    float unit=0;
    float money=0;
    int dt;

    printf("If the customer would like a space with recharging, input 1n");
    printf("If not,input 2n");
    while (scanf("%d", &option) != 1 && (option<1 || option>2))		
			{
			printf("Invalid entrynn");
			Sleep(2000);
			fflush(stdin);
			}

    fptr=fopen("unit_price.txt","rb");
    fread(&bike,sizeof(struct unit_price),1,fptr);

    if(option==1)
    {
        unit=bike.e_recharge;

    }
    else
    {
        unit=bike.e_no_recharge;
    }
    fflush(stdin);
    printf("Please input the duration(s):");
    scanf("%d",&dt);
    money=dt*unit;
    printf("the total money is %f",money);
    Sleep(2000);
    return;
}

void charge()
{
    fflush(stdin);
    FILE*fptr;
    struct customer_details account;
    float money=0;
    char filename[19]="";

    printf("Please enter customer's name:n");
    while (fgets(filename,19,stdin) == NULL)
	{
		fflush(stdin);
		printf("Something went wrong with the input, please try again:nnt");
	}

	filename[strlen(filename)-1]='';
	fflush(stdin);

    while((fptr=fopen(filename,"rb"))==NULL)
	{
		printf("This account does not exist or cannot open itn");
		return;
	}

    fread(&account,sizeof(struct customer_details),1,fptr);
    fclose(fptr);

    fflush(stdin);
    printf("Please input the money that the customer cost:");
    while(scanf("%f",&money)==0)
    {
        printf("Your input is wrong,please try againn");
        return;
    }
    account.account_balance-=money;
    fptr=fopen(filename,"wb");


    fwrite(&account,sizeof(struct customer_details),1,fptr);
    fclose(fptr);
    printf("Successn");
    return;
}

void create()
{
    char filename[25]="";
	struct customer_details customer;	  	  	  
    char code1[12],code2[12]="";
	FILE *fptr;					
    int m=1;//to control the while loop
    char ID_number[20]="";
    char pnumber[20]="";
    float money=0;
    char idenity[9]="";

   	fflush(stdin);
	system("cls");

	printf("Please enter the name of the playern");
    printf("the length of the name should be less than 19 digits:nnt");	 	 	 

	while (fgets(filename,19,stdin) == NULL)
		{
		fflush(stdin);
		printf("Something went wrong with the input, please try again:nnt");
		}
    filename[strlen(filename)-1]='';
    fflush(stdin);
    strcpy(customer.name,filename);//copy filename and send it into the struct tester
    printf("%s",filename);


 if((fptr=fopen(filename,"rb"))==NULL)//when we find there is no exit input filename

       {

       if((fptr=fopen(filename,"wb"))==NULL)//create a new file
           {
              printf("cannot establish the filen");
               return ;
           }
       }


    while(m==1)
    {
	printf("Please enter the password:n");
	printf("Warning: no space in the password!!!nt");
	while (scanf("%s", code1) == 0)
		{
		fflush(stdin);
		printf("Please try again and make sure the number has less than 19 digits");
		}
    printf("Please enter the same code again:nnt");
	while (scanf("%s", code2) == 0)
		{
		fflush(stdin);
		printf("Please try again and make sure the number has less than 19 digits");
		}
    if(strcmp(code1,code2))
    {
        printf("two inputs are not the same, please try again");
    }
    else
    {
        printf("welldonen");
        strcpy(customer.code,code1);
        m=0;
    }
    }

    printf("Please input your ID numbern");
    while(scanf("%s",ID_number)==0)
    {
        fflush(stdin);
		printf("Please try again and make sure the number has less than 19 digits");
    }
    strcpy(customer.university_ID,ID_number);

    printf("Please input your phone numbern");
    while(scanf("%s",pnumber)==0)
    {
        fflush(stdin);
		printf("Please try again and make sure the number has less than 19 digits");
    }
    strcpy(customer.phone_number,pnumber);

    printf("Please input the money you want to rechargen");
    while(scanf("%f",&money)==0)
    {
        fflush(stdin);
		printf("Please try again and make sure the number has less than 8 digits");
    }
    customer.account_balance=money;

    printf("Please input your status:students or teachern");
    while(scanf("%s",idenity)==0)
    {
        fflush(stdin);
		printf("Please try again and make sure the number has less than 8 digits");
    }
    strcpy(customer.status,idenity);

	fflush(stdin);
    fclose(fptr);

	
	fptr = fopen(filename, "wb+");

	if (fptr == NULL) 		
		{
		printf("nnThere was a problem opening the file, please restart the programnn");
		Sleep(2000);
		exit(0);
		}
	else			
		fwrite(&customer, sizeof(customer), 1, fptr);

	fclose(fptr); 		

	return;
}

void view()
{
     fflush(stdin);

    char filename[25]="";
    FILE *fptr;//declear the struct account pointer
    struct customer_details a,b;



    printf("nplease input the account name:n");
    while (fgets(filename,19,stdin) == NULL)//input the name
		{
		fflush(stdin);
		printf("Something went wrong with the input, please try again:nnt");
		}

    filename[strlen(filename)-1]='';
	strcpy(a.name,filename);//copy the name we just input to filename

	fptr=fopen(filename,"rb");
	if (fptr == NULL)
	{
		printf("This account does not exist");
		return;
	}
    fread(&b,sizeof(struct customer_details),1,fptr);//write fptr's content to account b

    //judge whether the name existence or not

	printf("please input the passwordn");
	scanf("%s",a.code);
	fflush(stdin);

  //judge whether the password right or not
	while (1)
	{
		if(strcmp(a.code,b.code)==0)
		{
			fclose(fptr);
			printf("welldone, you can review your game historyn");
			Sleep(500);
			break;
		}
		else
		{
			printf("the password is wrong, please input againn");
			scanf("%s",a.code);
		}
	}

    printf("%s's accountn",b.name);
    printf("tUniversity ID:%sn",b.university_ID);
    printf("tphone number:%sn",b.phone_number);
    printf("taccount balance:%gn",b.account_balance);
    printf("tstatus:%sn",b.status);
    Sleep(2000);

    fflush(stdin);
    return;
}

void carpark()
{
     int space[5][144]={0};
    int floor,i,j=0;
    FILE*fptr;

    srand(time(0));

    if((fptr=fopen("carspace.txt","r"))==NULL)
       {
           printf("Cannot open the filen");
       }


    while(floor<5)
    {

        for(j=0;j<143;j++)
          {
            fscanf(fptr,"%d",&space[floor][j]);
          }
          floor++;
    }
    fclose(fptr);

    floor=0;

        floor=rand()%5;
        i=rand()%144;//choose one floor randomly
        while(space[floor][i]==1)//judge whether the space is full or not
        {
            floor=rand()%5;
            i=rand()%144;//if it's full,choose again
        }
        space[floor][i]=1;//if not, make it full

floor=0;
  if((fptr=fopen("carspace.txt","w"))==NULL)
       {
           printf("Cannot open the filen");
       }
    while(floor<5)
    {

        for(j=0;j<144;j++)//write the array in the space.txt
          {

            fprintf(fptr,"%d ",space[floor][j]);
          }
          floor++;
    }

    floor=0;

while(floor<5)
{

  for(j=0;j<144;j++)
  {
    if(space[floor][j]==1)
    {
        printf("n%d floor %d number has been filledn",floor+1,j+1);
    }

  }
  floor++;
}
    Sleep(2000);
    fclose(fptr);
    return;
}

//View current car-park occupation and number of free spaces
void cheakcar()
{
    int space[5][144]={0};
    int j=0;
    int floor=0;
    FILE*fptr;

    if((fptr=fopen("carspace.txt","r"))==NULL)
       {
           printf("Cannot open the filen");
       }
while(floor<5)
{

    for(j=0;j<144;j++)
      {
        fscanf(fptr,"%d",&space[floor][j]);
      }
      floor++;
}
    fclose(fptr);
floor=0;

  while(floor<5)
{

  for(j=0;j<144;j++)
  {
    if(space[floor][j]==1)
    {
        printf("n%d floor %d number has been filledn",floor+1,j+1);
    }

  }
  floor++;
}
Sleep(2000);
}

void bikepark()
{
     int space[60]={0};
    int i,j=0;
    FILE*fptr;

    if((fptr=fopen("bikespace.txt","r"))==NULL)
       {
           printf("Cannot open the filen");
       }

    for(j=0;j<60;j++)
      {
        fscanf(fptr,"%d",&space[j]);
      }

    fclose(fptr);

    srand(time(0));


        i=rand()%60;//choose one floor randomly
        while(space[i]==1)//judge whether the space is full or not
        {
            i=rand()%60;//if it's full,choose again
        }
        space[i]=1;//if not, make it full




  if((fptr=fopen("bikespace.txt","w"))==NULL)
       {
           printf("Cannot open the filen");
       }
    for(j=0;j<60;j++)//write the array in the space.txt
      {
        fprintf(fptr,"%d ",space[j]);
      }
  for(j=0;j<60;j++)
  {
    if(space[j]==1)
    {
        printf("nground %d is filledn",j+1);
    }

  }
    Sleep(2000);
    fclose(fptr);
    return;
}

void free_bikepark()
{
   fflush(stdin);
   int option=0;
   int j,i=0;
   int space[60]={0};
   FILE*fptr;

   if((fptr=fopen("bikespace.txt","r"))==NULL)
       {
           printf("Cannot open the filen");
       }
   for(j=0;j<60;j++)
      {
        fscanf(fptr,"%d",&space[j]);
      }
  fclose(fptr);

   printf("Please input the floor you want to free:");
   while (scanf("%d", &option) != 1 && (option<1 || option>60))		
			{
			printf("Invalid entrynn");
			Sleep(2000);
			fflush(stdin);
			}
    space[option-1]=0;

    if((fptr=fopen("space.txt","w"))==NULL)
       {
           printf("Cannot open the filen");
       }

    for(i=0;i<60;i++)
      {
        fprintf(fptr,"%d ",space[i]);
      }
  fclose(fptr);
    printf("the %d number has been free",option);
    return;
}

void chargepark()
{
     int space[120]={0};
    int i,j=0;
    FILE*fptr;

    if((fptr=fopen("chargespace.txt","r"))==NULL)
       {
           printf("Cannot open the filen");
       }

    for(j=0;j<120;j++)
      {
        fscanf(fptr,"%d",&space[j]);
      }

    fclose(fptr);

    srand(time(0));


        i=rand()%120;//choose one floor randomly
        while(space[i]==1)//judge whether the space is full or not
        {
            i=rand()%120;//if it's full,choose again
        }
        space[i]=1;//if not, make it full




  if((fptr=fopen("chargespace.txt","w"))==NULL)
       {
           printf("Cannot open the filen");
       }
    for(j=0;j<120;j++)//write the array in the space.txt
      {
        fprintf(fptr,"%d ",space[j]);
      }
  for(j=0;j<120;j++)
  {
    if(space[j]==1)
    {
        printf("nground %d is filledn",j+1);
    }

  }
    Sleep(2000);
    fclose(fptr);
    return;
}

void free_chargepark()
{
   fflush(stdin);
   int option=0;
   int j,i=0;
   int space[120]={0};
   FILE*fptr;

   if((fptr=fopen("chargespace.txt","r"))==NULL)
       {
           printf("Cannot open the filen");
       }
   for(j=0;j<120;j++)
      {
        fscanf(fptr,"%d",&space[j]);
      }
  fclose(fptr);

   printf("Please input the floor you want to free:");
   while (scanf("%d", &option) != 1 && (option<1 || option>120))		
			{
			printf("Invalid entrynn");
			Sleep(2000);
			fflush(stdin);
			}
    space[option-1]=0;

    if((fptr=fopen("chargespace.txt","w"))==NULL)
       {
           printf("Cannot open the filen");
       }

    for(i=0;i<120;i++)
      {
        fprintf(fptr,"%d ",space[i]);
      }
  fclose(fptr);
    printf("the %d number has been free",option);
    return;
}
void free_carpark()
{
   fflush(stdin);
   int option1,option2=0;
   int j,i=0;
   int space[5][144]={0};
   FILE*fptr;
   int floor=0;

   if((fptr=fopen("space.txt","r"))==NULL)
       {
           printf("Cannot open the filen");
       }
while(floor<5)
{

   for(j=0;j<5;j++)
      {
        fscanf(fptr,"%d",&space[floor][j]);
      }
      floor++;
}
  fclose(fptr);

   printf("Please input the floor you want to free:");
   while (scanf("%d", &option1) != 1 && (option1<1 || option1>5))		
			{
			    fflush(stdin);
			    while(scanf("%d",&option2)!=1&&(option2<1||option2>144))
                {
                    printf("Invalid entrynn");
                    Sleep(2000);
                    fflush(stdin);
                }
			}
    space[option1-1][option2-1]=0;

    if((fptr=fopen("space.txt","w"))==NULL)
       {
           printf("Cannot open the filen");
       }
floor=0;
while(floor<5)
{

    for(i=0;i<144;i++)
      {
        fprintf(fptr,"%d ",space[floor][i]);
      }
      floor++;
}
  fclose(fptr);


    Sleep(2000);
    printf("n%d floor %d number has been filledn",option1,option2);
    return;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/689923.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号