A simple C program

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果无法连接一个简单的C程序,可能有几个可能的原因。 首先,确保你的代码中没有语法错误。检查是否正确使用了所有的括号、分号、变量和函数名,并且没有拼写错误。语法错误可能导致编译器无法将程序链接在一起。 其次,检查是否正确包含了所需的库。如果程序使用了库函数,但在代码中未正确包含相关的头文件,那么编译器将无法找到对应的函数定义,从而导致连接错误。 此外,检查是否在同一目录下有所有必要的源文件。如果程序的不同部分分别在不同的文件中编写,那么确保将所有文件一起编译和连接,以确保程序能够正确连接。 还有一个可能性是,在编译程序时提供了错误的链接选项。链接选项告诉编译器链接器应该如何查找和连接程序中使用的函数和库。如果提供的选项不正确,编译器可能无法找到所需的函数定义,从而导致连接错误。 最后,如果上述步骤都无法解决问题,可能是因为编译器本身存在问题。在这种情况下,尝试使用另一个编译器或更新已安装的编译器版本可能有助于解决问题。 总结起来,无法连接一个简单的C程序可能是由于语法错误、缺少库、缺少源文件、错误的链接选项或编译器问题等导致的。仔细检查并确保代码正确无误,并正确配置编译器选项可能有助于解决这个问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值