A simple C program

关于出现The C complier "/usr/bin/cc" is not able to complie a simple test program 的错误处理 MacOs在装完Clion之后需要安装编译器才可以正常对程序进行编译。 在安装完Cmake和Xcode之后遇到了这样的问题: 原因是没有licence 在终端输入:sudoxcodebuild -license 输入完密码之后,就会出现如下一长串的类似协议的文字,最后一行有如下提示: 这时候只要一直按空格就行了,直到出现: 这时候只要在尾端输入: agree 然... 阅读详情

#include<stdio.h>//printf()scanf()fflush(),fread(),fwrite()fopen()fclose(),fprintf(),fscanf(),
#include<string.h>//strcpy()memcpy()
#include<time.h>//time(),
#include<stdlib.h>//system(),srand(),random(),
#include<windows.h>//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();	  	  	  	  /*A function to create a new item in the telephone directory*/
void view(); 	  	  	  	  /*A function that finds an entry in the file and prints the information*/

//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))		/* Display menu and get user entry - check user entry validity*/
			{
			printf("Invalid entry\n\n");
			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 4\n");
         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))		/* Display menu and get user entry - check user entry validity*/
			{
			printf("Invalid entry\n\n");
			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 3\n");
              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))		/* Display menu and get user entry - check user entry validity*/
			{
			printf("Invalid entry\n\n");
			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 3\n");
              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))		/* Display menu and get user entry - check user entry validity*/
			{
			printf("Invalid entry\n\n");
			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 6\n");
              Sleep(2000);
    }
}

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

    while (scanf("%d", &all) != 1 && (all<1 || all>5))		/* Display menu and get user entry - check user entry validity*/
			{
			printf("Invalid entry\n\n");
			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 5\n");
              Sleep(2000);

    }
}

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

    while(scanf("%d",&all)!=1&&(all<1||all>6))
        {
			printf("Invalid entry\n\n");
			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 6\n");
              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 waiting\n");
            m=0;
            Sleep(2000);
        }
        else
        {
            printf("the password is wrong, please enter again\n");
        }
    }
    return;
}


void welcomemenu()
{
    printf("welcome to Parking Management System\n");
    printf("please choose your identity\n");
    printf("The input should be number ,others are illegal\n");
    printf("\t1.customer\n");
    printf("\t2.admin\n");
    printf("\t3.worker\n");
    printf("\t4.quit\n");
}

void adminmenu()
{
    printf("welcome to Parking Management System's admin menu\n");
    printf("please make your choice\n");
    printf("The input should be number ,others are illegal\n");
    printf("\t1.change the account\n");
    printf("\t2.set the parking parameter\n");
    printf("\t3.Back to previous page\n");
}

void custmenu()
{
    printf("welcome to Parking Management System\n");
    printf("please make your choice\n");
    printf("The input should be number ,others are illegal\n");
    printf("\t1.create a new account\n");
    printf("\t2.view the account\n");
    printf("\t3.Back to previous page\n");
}

void workermenu()
{
    printf("welcome to Parking Management System\n");
    printf("please make your choice\n");
    printf("The input should be number ,others are illegal\n");
    printf("\t1.operation about the car \n");
    printf("\t2.operations for an e-bike\n");
    printf("\t3.Charge the leaving customer accordingly\n");
    printf("\t4.Record the entry of a registered customer\n");
    printf("\t5.Look through the information recorded\n");
    printf("\t6.Back to previous page\n");

}

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

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

}

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 name\n");
  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:\n\n\t");
		}
  filename[strlen(filename)-1]='\0';

  fflush(stdin);

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

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

  printf("Please input your password\n");
   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 number\n");
    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 number\n");
    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 balance\n");
    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 status\n");
    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);

	/*Once all of the member information has been collected, the file is opened ready to append the new entry at the end of the file*/
	fptr = fopen(filename, "wb+");

	if (fptr == NULL) 		/*Test the success of opening the file*/
		{
		printf("\n\nThere was a problem opening the file, please restart the program\n\n");
		Sleep(2000);
		exit(0);
		}
	else			/*On successfully opening the file the structure is written to the file*/
		fwrite(&customer, sizeof(customer), 1, fptr);

	fclose(fptr); 		/*Close the file*/


}

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:\n\n\t");
	}

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

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

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


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

    strcpy(account.entry,input);
    printf("You have recorded the entry\n");
    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:\n\n\t");
	}

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

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

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

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


}

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 %f\n",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 1\n");
    printf("If not,input 2\n");
    while (scanf("%d", &option) != 1 && (option<1 || option>2))		/* Display menu and get user entry - check user entry validity*/
			{
			printf("Invalid entry\n\n");
			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:\n\n\t");
	}

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

    while((fptr=fopen(filename,"rb"))==NULL)
	{
		printf("This account does not exist or cannot open it\n");
		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 again\n");
        return;
    }
    account.account_balance-=money;
    fptr=fopen(filename,"wb");


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

void create()
{
    char filename[25]="";
	struct customer_details customer;	  	  	  /*declare a structure*/
    char code1[12],code2[12]="";
	FILE *fptr;					/*declare a file pointer*/
    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 player\n");
    printf("the length of the name should be less than 19 digits:\n\n\t");	 	 	 /*Obtain each structure member information checking each for validity*/

	while (fgets(filename,19,stdin) == NULL)
		{
		fflush(stdin);
		printf("Something went wrong with the input, please try again:\n\n\t");
		}
    filename[strlen(filename)-1]='\0';
    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 file\n");
               return ;
           }
       }


    while(m==1)
    {
	printf("Please enter the password:\n");
	printf("Warning: no space in the password!!!\n\t");
	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:\n\n\t");
	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("welldone\n");
        strcpy(customer.code,code1);
        m=0;
    }
    }

    printf("Please input your ID number\n");
    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 number\n");
    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 recharge\n");
    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 teacher\n");
    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);

	/*Once all of the member information has been collected, the file is opened ready to append the new entry at the end of the file*/
	fptr = fopen(filename, "wb+");

	if (fptr == NULL) 		/*Test the success of opening the file*/
		{
		printf("\n\nThere was a problem opening the file, please restart the program\n\n");
		Sleep(2000);
		exit(0);
		}
	else			/*On successfully opening the file the structure is written to the file*/
		fwrite(&customer, sizeof(customer), 1, fptr);

	fclose(fptr); 		/*Close the file*/

	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:\n\n\t");
		}

    filename[strlen(filename)-1]='\0';
	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 password\n");
	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 history\n");
			Sleep(500);
			break;
		}
		else
		{
			printf("the password is wrong, please input again\n");
			scanf("%s",a.code);
		}
	}

    printf("%s's account\n",b.name);
    printf("\tUniversity ID:%s\n",b.university_ID);
    printf("\tphone number:%s\n",b.phone_number);
    printf("\taccount balance:%g\n",b.account_balance);
    printf("\tstatus:%s\n",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 file\n");
       }


    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 file\n");
       }
    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 filled\n",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 file\n");
       }
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 filled\n",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 file\n");
       }

    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 file\n");
       }
    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 filled\n",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 file\n");
       }
   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))		/* Display menu and get user entry - check user entry validity*/
			{
			printf("Invalid entry\n\n");
			Sleep(2000);
			fflush(stdin);
			}
    space[option-1]=0;

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

    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 file\n");
       }

    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 file\n");
       }
    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 filled\n",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 file\n");
       }
   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))		/* Display menu and get user entry - check user entry validity*/
			{
			printf("Invalid entry\n\n");
			Sleep(2000);
			fflush(stdin);
			}
    space[option-1]=0;

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

    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 file\n");
       }
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))		/* Display menu and get user entry - check user entry validity*/
			{
			    fflush(stdin);
			    while(scanf("%d",&option2)!=1&&(option2<1||option2>144))
                {
                    printf("Invalid entry\n\n");
                    Sleep(2000);
                    fflush(stdin);
                }
			}
    space[option1-1][option2-1]=0;

    if((fptr=fopen("space.txt","w"))==NULL)
       {
           printf("Cannot open the file\n");
       }
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 filled\n",option1,option2);
    return;
}

从零实现地震波场模拟:交错网格有限差分法核心代码精讲 本文详细介绍了从零实现地震波场模拟的核心技术,重点讲解了交错网格有限差分法的实现过程。通过速度-应力弹性波方程的离散化处理,结合代码实例演示了应力与速度更新的关键步骤,并分享了震源加载、稳定性条件等实用技巧,为计算地球物理学研究提供实践指导。 阅读详情

相关推荐

erdas监督分类(二)

去云 用一张没有云的影像替代有云影像 构建aoi图层 将云和云影编码合并 重编码工作 在监督分类做的差不多以后(纠正无误,无明显错误),就要对监督分类图像进行重编码和颜色调整。 在中选中Recode,对原来分类的地物类别进行重编码,(为彻底修改,记得备份)选中一列,在New Value输入新的编码,依次编码后点击应用apply,即可实现。 这时的图像如果是全黑的或者只有一两类的颜色也没有关系,新的编码覆盖掉了原来的编码,但是颜色并没有改变才会这样。可以点击图像,右击...

weixin_58968530的博客 958

C&C++学习笔记2

《C Primer Plus 5th Edition》摘录 Object Code Files,Executable Files,and Libraries basic strategy:  use programs that convert your source code file to an executable file ,which is a file containing r

Laynalute的博客 593

【域控制器EMC】域控制器EMC设计总结

汇总项目设计当中关于EMC的设计要点,主要从原理设计、Layout、结构、外设部分总结。满足要求的器件和合理的电路能降低电磁干扰;正确的布局、接地、信号路径、屏蔽等可以减少电磁辐射。结构件设计也会对EMC性能产生影响。

weixin_42098658的博客 1259

python计算器程序,python计算器程序

I wrote a simple calculator program by using functions, I don't know what exactly wrong with this code, its showing error. I did possible steps to debug this, but I couldn't.#!/usr/bin/pythondef add()...

weixin_29313239的博客 116

WRF气象建模实战:如何为JRA55非标准数据定制Vtable文件?

本文详细介绍了为WRF气象模型定制Vtable文件以支持JRA55非标准数据(特别是积雪数据)的完整实战流程。文章深入解析了WPS数据流中Vtable的核心映射逻辑,提供了从GRIB文件诊断、Vtable编写到METGRID.TBL调优的通用方法论,帮助用户解决非标准气象数据源适配的关键技术挑战。

c8d9e0f1的博客 673

STM32G030C8T6 ADC+DMA实战:同时采集外部电压和芯片温度的完整代码流程

本文详细介绍了STM32G030C8T6芯片通过ADC+DMA实现外部电压和芯片内部温度采集的完整流程。从硬件设计到CubeMX配置,再到驱动模块化实现与系统优化,提供了高精度多通道采集系统的实战指南,特别适合嵌入式开发者在工业控制和环境监测项目中应用。

weixin_42653691的博客 467

Samba TDB 数据库 在嵌入式中的使用

Samba stores its data in TDB files. TDB stands for "Trivial database" 其他相关的数据库的介绍可以参考这个链接: https://www.jianshu.com/p/8bb2c9d8d90c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation ...

paky_du的专栏 2595

级联H桥构网型储能SVG系统设计与VSG控制策略研究

随着新能源渗透率不断提高,电力系统惯量和阻尼水平持续下降,传统跟网型控制策略在弱电网条件下的稳定性面临严峻挑战。构网型控制以电压源方式运行,能够为系统提供惯量和频率支撑,成为当前研究热点。本文针对10kV/10Mvar级联H桥构网型储能静止无功发生器(SVG),采用星形连接拓扑结构,设计了基于虚拟同步发电机(VSG)的构网型控制策略。文章从主电路拓扑设计、数学建模、VSG控制策略设计、调制策略、直流电压平衡控制、系统参数设计、仿真建模和硬件实现等八个方面展开系统论述,给出了完整的Simulink仿真模型~~

huanghm88的专栏 349

RuntimeError: Broken toolchain: cannot link a simple C program

今天Python2.7下安装numpy的时候遇到了此错误,进过查阅发现以下方法可行 在Python27\Lib\distutils\msvc9compiler.py 文件中,找到 mfinfo = self.manifest_get_embed_info(target_desc, ld_args)行将其改为 mfinfo=none 详细请查看这里 转载于:https://www.cn...

weixin_30340775的博客 3874

《测绘综合能力》——大地测量

《测绘综合能力》大地测量 部分重要(常考)知识点(精简版)。

C_xxy's blog 803

YOLO26 旋转框检测 OBB 技术:角度预测与解码优化

YOLO26旋转框检测技术通过CSL角度编码有效解决了OBB检测中的周期性问题。该技术采用5参数表示法(cx,cy,w,h,θ),在检测头中分别处理分类、回归和角度预测。核心创新点包括:1)使用高斯或三角窗口的CSL编码对角度进行平滑表示;2)通过加权平均解码角度,避免边界不连续问题。该方法在遥感、文本检测等需要精确方向信息的场景中表现优异,相比传统HBB框可提升定位精度30%以上,同时保持了YOLO系列的高效特性。

一键难忘的博客 521

关于cmake is not able to compile a simple test program

指定了交叉编译 set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_FIND_ROOT_PATH "/opt/mips/eldk4.1/usr/bin") set(CMAKE_C_COMPILER "${CMAKE_FIND_ROOT_PATH}/mips_4KC-gcc") 但报错compile tools can not be able to bu

风之伤 3万+

XCP详解「3.1·ASAP2新建A2L文件」

后面是ASAP2新建A2L的操作步骤,如果是APE中新建的A2L就无需以下操作,APE只需要导入现成的A2L即可。退出点击保存时会提示保存A2L文件,是因为前面导出的是1.70版本,工程最低1.71,可以另外起个名字即可。导入elf文件,elf路径建议直接索引编译生成的Debug下的,防止编译后忘记更新。导出V1.70格式A2L文件,APE17支持V1.70。通过ASAP2生成需要A2L文件更常用些。同一个信号可以创建不同属性量。ASAP2中新建A2L文件。设置标定信号数量最大值。XCP详解「总目录」

光明磊学习&积累的地方 3059

安装numpy时报错RuntimeError: Broken toolchain: cannot link a simple C program

install numpy RuntimeError: Broken toolchain: cannot link a simple C program

pythonwahaha的博客 3878

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

A simple C program(hangman)

C语言大作业,hangman,吊死鬼游戏,包含创建账户,登陆系统,查询历史。

c_type的博客 1048

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

解决macos下clion报错:The C complier “/usr/bin/cc“ is not able to complie a simple test program

解决macos下clion报错:The C complier “/usr/bin/cc“ is not able to complie a simple test program 报错截图: 原因:command line tools更新了,不匹配,更新command line tools就好。 下载地址:https://developer.apple.com/download/more/ 下载完了安装就行。然后去clion里面点击:Tools->CMake->Reload CMake Pro

xqacmer 1873

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

a very simple C program in Visual Studio 2005

http://stackoverflow.com/questions/2548361/very-simple-c-program-wont-compile-with-vc-64 http://forums.nvidia.com/index.php?showtopic=65111&pid=398501&mode=threaded&show=&st=& He...

weixin_30879169的博客 83

The C compiler is not able to compile a simple test program.

在CMakeLists.txt中project之前加入 set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY") 参考: gcc - CMake: The C Compiler is not able to compile a simple test program - Stack Overflow

flashlau的专栏 3132

mac The C compiler is not able to compile a simple test program.

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 欢迎使用Markdown编辑器 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar

weixin_41414657的博客 1447

Mac OS 安装tensorflow RuntimeError: Broken toolchain: cannot link a simple C program

Mac OS 安装tensorflow RuntimeError: Broken toolchain: cannot link a simple C programMac OS 安装tensorflow的时候碰到的问题 RuntimeError: Broken toolchain: cannot link a simple C program这个其实是pip 在更新numpy的时候出的问题。解决方

luyee2010的专栏 7758

cmake编译ITK报错:The C compiler is not able to compile a simple test program

cmake编译ITK时出现如下错误: The C compiler identification is MSVC 19.0.23026.0 Check for working C compiler: E:/Microsoft Visual Studio 14.0/VC/bin/cl.exe Check for working C compiler: E:/Microsoft Visual

兔子先生的博客 1万+

opencv交叉编译 和 The C/C++ compiler is not able to compile a simple test program.

本文笔者将介绍在ubuntu18.04环境如何交叉编译opencv4.5.3,内容涉及常见编译不通过的规避方法,以及“CMAKE_SYSTEM_PROCESSOR is not defined.”、“compiler broken”、“ The C/C++ compiler is not able to compile a simple test program.”的解决方法。

石大侠 6496

The C compiler “xxx“ is not able to compile a simple test program.一种可能的解决方法

The C compiler "xxx" is not able to compile a simple test program.一种可能的解决方法

chengxiaili的博客 3684

Clion STM32 GNU Cmake报错 The C compiler is not able to compile a simple test program.解决

【代码】Clion STM32 GNU Cmake报错 The C compiler is not able to compile a simple test program.解决。

qq_39765790的博客 3034
上一篇: A simple C program(hangman)
下一篇: 题目非原创
c_type
博客等级 码龄5年 0粉丝 9原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值