C language array to implement the bus management system

  • 2020-06-23 01:37:09
  • OfStack

This paper shares the specific code of C language bus management system for your reference. The specific content is as follows


/************************** Header file declaration ************************************/
 
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "conio.h"
 
/************************** Function declaration ************************************/
 
void init();           // Initialization function 
void add();             // Information entry function 
void view();             // Information display function 
void mod();             // Information modification function 
void modmeun();           // Modify the menu 
void modnavimeun();         // Route Modification menu 
void del();             // Message deletion function 
void find();             // Information query function 
void findmeun();           // Query menu 
void findnavi();           // Route navigation query function 
void findnum();           // Route number query function 
void findstameun();         // Platform information query menu 
void findsta();           // Platform information query function 
void save();             // Information saving function  
void mainmeun();           // The main menu 
char Test(char a,char b,char c);   // Menu input detection function 
 
/************************** Macro definition declaration ************************************/
#define N 100          // Number of buses 
 
/************************** Structural definition ************************************/
struct station          // Channel site information 
{
 char c[20];         // The site name 
};
 
struct bus            // Bus information 
{
 char num[20];        // Bus route number 
 char name[20];        // The driver's name 
 int n;            // The platform number 
 struct station b[12];    // Name of the platform 
 char topen[20];       // Starting time 
 char tclose[20];       // End time 
 int money;          // The fare 
}a[N];
 
 
/************************** The function definitions ************************************/
 
int main()
{
 char a;
 init();
 printf("\n\t\t At present, the maximum number of buses can be recorded is  %d  car \n\n",N);
 printf("\n\t\t Enter enter to continue \n");
 fflush(stdin);              // Clear keyboard buffer 
 while(1)
 {
 system("cls");
 mainmeun();
 a=Test(getchar(),'1','6');   // Menu detects input functions  
 switch(a)
 {
 case '1': system("cls"); add(); break;
 case '2': system("cls"); view(); break;
 case '3': system("cls"); mod(); break;
 case '4': system("cls"); del(); break;
 case '5':  system("cls"); find(); break;
 case '6':  return 0;
 }
 }
 return 0;
}
 
void init()   // Initialization function     
{
 FILE *fp;            // The file pointer 
 int i;
 if((fp=fopen("bus.txt","r+"))==NULL)         // First attempt to open "bus.txt" Text file 
 {
 printf("\n\t\t File opening failed \n\n\t\t Trying to create a new file ...\n");
 fp=fopen("bus.txt","w");             // create "bus.txt" Text file 
 if((fp=fopen("bus.txt","r+"))==NULL)       // Again, determine if the opening was successful 
 {
  printf("\t\t File creation failed !!!\n");
  return;
 }
 }
 fp=fopen("bus.txt","r+");
 for(i=0;i<N;i++)                     // Outputs information from the disk into memory 
 if(fread(&a[i],sizeof(struct bus),1,fp)!=1)
  break;
 fclose(fp);
 printf("\n\t\t Initialization is complete !!!\n\n");
 return;
}
 
void add()   // Information entry function    
{
 FILE *fp=NULL;            // The file pointer 
 int i,j;
 char cc[20];
 for(i=0;i<N;i++)
 {
 if(*a[i].num!='\0')
  continue;
 else
 {
  printf("\n Add the first %d A bus route record :\n",i+1);                
  printf("\n Please enter the route code (3 Bit coding, number 1 The digits are capital letters and the last two digits are Numbers ):\n");  // Line coding 
  scanf("%s",cc);
  for(j=0;j<N;j++)                              // Check for duplication 
  if(strcmp(a[j].num,cc)==0)
  {
   printf("\n Repeat with the existing route code, press enter to return !!!\n");
   fflush(stdin);              // Clear keyboard buffer 
   getchar();
   system("cls");
   return;
  }
  strcpy(a[i].num,cc);
  printf("\n Please enter the driver's name : ");                       // The driver's name 
  scanf("%s",a[i].name);
  printf("\n Please enter the total number of channels (>=2): ");                   // The total number of the platform 
  scanf("%d",&a[i].n);
  printf("\n");
  if(a[i].n<2||a[i].n>12)
  {
  while(a[i].n<2||a[i].n>12)
  {
   printf("\n The total number of stations should meet (2<=n<=12) , please re-enter : ");
   scanf("%d",&a[i].n);
   printf("\n");
  }
  }
  for(j=0;j<a[i].n;j++)
  {
  printf(" Please enter the first %d Name of each platform : ",j+1);          // Name of the platform 
  scanf("%s",a[i].b[j].c);
  }
  printf("\n Automatically generates bus routes :(1) %s",a[i].b[0].c);
  for(j=1;j<a[i].n;j++)
  {
  printf(" ----> (%d) %s",j+1,a[i].b[j].c);
  }
  printf("\n\n Please enter the start time of the bus ( Format: When : points ): ");    // Starting time 
  scanf("%s",a[i].topen);
  printf(" Please enter the end time of the bus ( Format: When : points ): ");      // End time 
  scanf("%s",a[i].tclose);
  printf("\n Please enter the fare of the bus : ");              // The fare 
  scanf("%d",&a[i].money);
  printf("\n The first %d Bus route record created successfully !!!\n",i+1);
  save();
  printf("\n\t Press enter to return !!!\n");
  fflush(stdin);              // Clear keyboard buffer 
  getchar();
  system("cls");
  return;
 }
 }
 if(i==N)
 printf("\n\n\n\t The space is full and cannot be entered !!!\n");
 printf("\n\t Press enter to return !!!\n");
 fflush(stdin);              // Clear keyboard buffer 
 getchar();
 system("cls");
 return;
}
 
 
void view()  // Information display function    
{
 int i,j,min;
 struct bus t;                  
 for(i=0;*a[i].num!='\0'&&i<N;i++)        // Sort by route number by selection 
 {
 min=i;
 for(j=i+1;*a[j].num!='\0'&&j<N;j++)
  if(strcmp(a[i].num,a[j].num)>0)
  min=j;
 t=a[i];
 a[i]=a[min];
 a[min]=t;
 }
 printf("\n\n                Bus information base ");
 printf("\n********************************************************************************\n");
 for(i=0;*a[i].num!='\0'&&i<N;i++)
 {
 printf("\t Route number : %-6s\t One-way fares : %d  yuan \t\t The driver's name : %s\n",a[i].num,a[i].money,a[i].name);
 printf("\t Starting time : %-6s\t End time : %-6s\t The total number of the platform : %d\n",a[i].topen,a[i].tclose,a[i].n);
 printf("\t Bus routes :(1) %s",a[i].b[0].c);
 for(j=1;j<a[i].n;j++)
  printf(" ---->(%d) %s",j+1,a[i].b[j].c);
 printf("\n\n");
 }
 printf("\n********************************************************************************\n");
 printf("\n\t\t The bus information is displayed !!!\n");
 printf("\n\t\t Enter the enter key to return to the main menu :");
 fflush(stdin);              // Clear keyboard buffer 
 getchar();
 system("cls");
 return;
}
 
 
 
void mod()             // Information modification function 
{
 int i,j,m=0;
 char t,cc[20],mod[20];
 printf(" Please enter the bus route number to modify the information :\n");
 scanf("%s",cc);
 for(i=0;*a[i].num!='\0'&&i<N;i++)   // Find the bus you entered 
 {
 if(strcmp(a[i].num,cc)==0)    
 {
  m=1;
  printf("\n\n\t\t Had been found !!!\n");
  while(1)
  {
  system("cls");
  printf("\n\n               Bus information being modified \n");
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
  printf("\t Route number : %-6s\t One-way fares : %d  yuan \t\t The driver's name : %s\n",a[i].num,a[i].money,a[i].name);
  printf("\t Starting time : %-6s\t End time : %-6s\t The total number of the platform : %d\n",a[i].topen,a[i].tclose,a[i].n);
  printf("\t Bus routes :(1) %s",a[i].b[0].c);
  for(j=1;j<a[i].n;j++)
   printf(" ---->(%d) %s",j+1,a[i].b[j].c);
  printf("\n\n");
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n");
  modmeun();
  fflush(stdin);              // Clear keyboard buffer 
  t=Test(getchar(),'1','5');   // Menu detects input functions  
  system("cls");
  switch(t)
  {
  case '1':      // Modified route number 
   {
   int k;
   printf("\n Please enter the new bus number :");
   scanf("%s",mod);
   for(k=0;*a[k].num!='\0'&&k<N;k++)
   {
    if(strcmp(a[k].num,mod)==0)
    {
    printf(" Repeat with an existing number , Press enter to return to the main menu \n");
    fflush(stdin);              // Clear keyboard buffer 
    getchar();
    system("cls");
    return;
    }
   }
   strcpy(a[i].num,mod);
   save();
   break;
   }
  case '2':      // Modify vehicle information 
   {
   printf("\n Please enter the new driver's name :");
   scanf("%s",a[i].name);
   printf("\n Please enter the new bus fare :");
   scanf("%d",&a[i].money);
   save();
   break;
   }
  case '3':      // Change of route 
   {
   void modnavimeun(); // Route Modification menu 
   int k;
   char z;
   while(1)
   {
    system("cls");
    modnavimeun();
    fflush(stdin);              // Clear keyboard buffer 
    z=Test(getchar(),'1','5');   // Menu detects input functions  
    system("cls");
    switch(z)
    {
    case '1':   // Add site 
    {
     if(a[i].n+1>12)       // Determine if the condition is met 
     {
     printf("\n The total number of platforms reached 12 Cannot add a new site \n\n Press enter to return \n");
     fflush(stdin);              // Clear keyboard buffer 
     getchar();
     system("cls");
     return;
     }
     printf("\n Please enter which site you want to add: ");
     scanf("%d",&k);
     while(a[i].n+1<k)
     {
     printf(" At present, a total of %d Site, unable to add %d A site \n Please re-enter: ",a[i].n,k);
     scanf("%d",&k);
     printf("\n");
     }
     a[i].n=a[i].n+1;
     for(j=a[i].n;j>k-1;j--)
     {
      a[i].b[j]=a[i].b[j-1];
     }
     printf("\n Please enter the name of the newly added site: ");
     scanf("%s",a[i].b[k-1].c);
     save();
     break;
    }
    case '2':   // Modify the site 
    {
     printf("\n Please enter which site you need to modify: ");
     scanf("%d",&k);
     printf("\n Please enter the new site name: ");
     scanf("%s",a[i].b[k-1].c);
     save();
     break;
    }
    case '3':   // Delete the site 
    {
     printf("\n Please enter which site you want to delete: ");
     scanf("%d",&k);
     for(j=k-1;j<a[i].n;j++)
     {
     a[i].b[j]=a[i].b[j+1];
     }
     a[i].n=a[i].n-1;
     save();
     break;
    }
    case '4':   // Reset the route 
    {
     printf("\n Please enter the total number of new channel stations (2<=n<=12): ");
     scanf("%d",&a[i].n);
     printf("\n");
     while(a[i].n<2||a[i].n>12)       // Determine if the condition is met 
     {
     printf("\n The total number of stations should meet (2<=n<=12) , please re-enter : ");
     scanf("%d",&a[i].n);
     printf("\n");
     }
     for(j=0;j<a[i].n;j++)
     {
     printf(" Please enter the new number %d Name of each platform : ",j+1);
     scanf("%s",a[i].b[j].c);
     }
     printf("\t Bus routes :(1) %s",a[i].b[0].c);
     for(j=1;j<a[i].n;j++)
     printf(" ---->(%d) %s",j+1,a[i].b[j].c);
     printf("\n\n");
     save();
     break;
    }
    case '5':   // Return to the menu 
    {
     printf("\n\t\t Press enter to return to the menu \n");
     fflush(stdin);              // Clear keyboard buffer 
     getchar();
     system("cls");
     return;              // Go back to the main menu 
    }
    }
   }
   }
  case '4':      // Modified travel time 
   {
   printf("\n\n Please enter the start time of the bus ( Format: When : points ): ");
   scanf("%s",a[i].topen);
   printf(" Please enter the end time of the bus ( Format: When : points ): "); 
   scanf("%s",a[i].tclose);
   save();
   break;
   }
  case '5':
   {
   printf("\n\t\t Press enter to return to the main menu \n");
   fflush(stdin);              // Clear keyboard buffer 
   getchar();
   system("cls");
   return;              // Go back to the main menu 
   }
  }
  }
 }
 }
 if(m==0)
 printf("\n\n\t\t This bus information is not available !!!\n");
 printf("\n\t\t Press enter to return \n");
 fflush(stdin);              // Clear keyboard buffer 
 getchar();
 system("cls");
 return;
}
 
 
 
void modmeun() // Modify the menu 
{
 printf("\n\t\t          Modify the menu           ");
 printf("\n\t\t********************************************");
 printf("\n\t\t*      1 Modify route number         *");
 printf("\n\t\t*      2 Modify vehicle information         *");
 printf("\n\t\t*      3 Modify the route         *");
 printf("\n\t\t*      4 Modify the driving time         *");
 printf("\n\t\t*      5 , back to the main menu         *");
 printf("\n\t\t********************************************");
 printf("\n\n\t\t Please enter your choice :");
}
 
 
void modnavimeun() // Route Modification menu 
{
 printf("\n\t\t         Route Modification menu          ");
 printf("\n\t\t********************************************");
 printf("\n\t\t*      1 ,   standing   point   add   add         *");
 printf("\n\t\t*      2 ,   standing   point   repair   change         *");
 printf("\n\t\t*      3 ,   standing   point   delete   In addition to         *");
 printf("\n\t\t*      4 ,   Road,   line   heavy   buy         *");
 printf("\n\t\t*      5 ,   return   Back to the   food   single         *");
 printf("\n\t\t********************************************");
 printf("\n\n\t\t Please enter your choice :");
}
 
 
void del()    // Message deletion function 
{
 int i,j,t,m=0;
 char cc[20];
 printf("\n Please enter the bus route number for the deletion information :\n");
 scanf("%s",cc);
 for(i=0;*a[i].num!='\0'&&i<N;i++)   // Find the bus you entered 
 {
 if(strcmp(a[i].num,cc)==0)    
 {
  m=1;
  printf("\n Had been found :\n");
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
  printf("\t Route number : %-6s\t One-way fares : %d  yuan \t\t The driver's name : %s\n",a[i].num,a[i].money,a[i].name);
  printf("\t Starting time : %-6s\t End time : %-6s\t The total number of the platform : %d\n",a[i].topen,a[i].tclose,a[i].n);
  printf("\t Bus routes :(1) %s",a[i].b[0].c);
  for(j=1;j<a[i].n;j++)
  printf(" ---->(%d) %s",j+1,a[i].b[j].c);
  printf("\n\n");
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n");
  printf(" The bus information is about to be deleted !!!\n Sure please click 1 : ");
  scanf("%d",&t);
  if(t==1)
  {
  if(i+1==N)
   memset(&a[i],'\0',sizeof(struct bus));   // The last 1 The car is emptied directly 
  else
   for(j=i;*a[j].num!='\0'&&j+1<N;j++)     // The bus information in the back is supplemented with the deleted bus information 
   a[j]=a[j+1];
  printf(" Numbers for %s The deletion of bus information is completed !\n",cc);
  save();
  break;
  }
 }
 }
 if(m==0)
 printf("\n\n\t\t This bus information is not available !!!\n");
 printf("\n\n\t Enter the enter key to return to the main menu :");
 fflush(stdin);              // Clear keyboard buffer 
 getchar();
 system("cls");
 return;
}
 
 
void find()  // Information query function 
{
 char t;
 while(1)
 {
 findmeun();
 fflush(stdin);              // Clear keyboard buffer 
 t=Test(getchar(),'1','4');   // Menu detects input functions  
 switch(t)
 {
 case '1': system("cls"); findnavi();break;     // Route navigation query 
 case '2': system("cls"); findnum();break;     // Route number query function 
 case '3': system("cls"); findsta();break;     // Platform information query function 
 case '4': system("cls"); return;          // Go back to the main menu 
 }
 }
 return;
}
 
 
void findmeun() // Query menu 
{
 printf("\n\t\t          Query menu           ");
 printf("\n\t\t********************************************");
 printf("\n\t\t*      1 , route navigation query         *");
 printf("\n\t\t*      2 , route number query         *");
 printf("\n\t\t*      3 , platform information query         *");
 printf("\n\t\t*      4 , back to the main menu         *");
 printf("\n\t\t********************************************");
 printf("\n\n\t\t Please enter your choice :");
}
 
 
void findnavi()    // Route navigation query function 
{
 int i,j,k,m=0;
 char c1[20],c2[20];
 printf(" Please enter your current site :\n\t\t");
 scanf("%s",c1);
 printf(" Please enter the site you want to visit :\n\t\t");
 scanf("%s",c2);
 printf("\n\n The bus information of your choice is as follows \n");
 printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
 for(i=0;*a[i].num!='\0'&&i<N;i++)
 {
 for(j=0;j<a[i].n;j++)
  for(k=j+1;k<a[i].n;k++)
  if(strcmp(a[i].b[j].c,c1)==0&&strcmp(a[i].b[k].c,c2)==0)
  {
   m=1;
   printf("\n");
   printf("\t Route number : %-6s\t One-way fares : %d  yuan \t\t The driver's name : %s\n",a[i].num,a[i].money,a[i].name);
   printf("\t Starting time : %-6s\t End time : %-6s\t The total number of the platform : %d\n",a[i].topen,a[i].tclose,a[i].n);
   printf("\t Bus routes :(1) %s",a[i].b[0].c);
   for(j=1;j<a[i].n;j++)
   printf(" ---->(%d) %s",j+1,a[i].b[j].c);
   printf("\n\n");
  }
 }
 printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n");
 printf("\t\t\t\t interspersing \n");
 if(m==0)
 printf("\n\n\t\t\t\t I'm sorry , There are no buses on this route \n");
 printf("\n\t\t\t\t Enter the enter key to return to the query menu :");
 fflush(stdin);              // Clear keyboard buffer 
 getchar();
 system("cls");
 return;
}
 
 
void findnum()      // Route number query function 
{
 int i,j,m=0;
 char cc[20];
 printf(" Please enter the bus route number you want to find :\n");
 scanf("%s",cc);
 for(i=0;*a[i].num!='\0'&&i<N;i++)
 {
 if(strcmp(a[i].num,cc)==0)    
 {
  m=1;
  printf("\n Had been found :\n");
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
  printf("\t Route number : %-6s\t One-way fares : %d  yuan \t\t The driver's name : %s\n",a[i].num,a[i].money,a[i].name);
  printf("\t Starting time : %-6s\t End time : %-6s\t The total number of the platform : %d\n",a[i].topen,a[i].tclose,a[i].n);
  printf("\t Bus routes :(1) %s",a[i].b[0].c);
  for(j=1;j<a[i].n;j++)
  printf(" ---->(%d) %s",j+1,a[i].b[j].c);
  printf("\n\n");
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n");
  break;
 }
 }
 if(m==0)
 printf("\n\t\t This bus information is not available \n");
 printf("\n\t\t Enter the enter key to return to the query menu :");
 fflush(stdin);              // Clear keyboard buffer 
 getchar();
 system("cls");
 return;
}
 
 
 void findstameun() // Platform information query menu 
{
 printf("\n\t\t        Platform information query menu ");
 printf("\n\t\t********************************************");
 printf("\n\t\t*      1 , initial platform query         *");
 printf("\n\t\t*      2 , stop the platform query         *");
 printf("\n\t\t*      3 , channel platform query         *");
 printf("\n\t\t*      4 , return the query menu         *");
 printf("\n\t\t********************************************");
 printf("\n\n\t\t Please enter your choice :");
}
 
 
void findsta()    // Platform information query function 
{
 int i,j,k;
 char t;
 char cc[20];
 while(1)
 {
 int m=0;
 findstameun();
 fflush(stdin);              // Clear keyboard buffer 
 t=Test(getchar(),'1','4');   // Menu detects input functions  
 system("cls");
 switch(t)
 {
 case '1':
  {
  printf(" Please enter the name of the starting platform you want to query :\n");
  scanf("%s",cc);
  printf("\n In order to %s The buses for the starting platform are as follows :\n",cc);
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
  for(i=0;*a[i].num!='\0'&&i<N;i++)
  {
   if(strcmp(a[i].b[0].c,cc)==0)
   {
   m=1;
   printf("\n");
   printf("\t Route number : %-6s\t One-way fares : %d  yuan \t\t The driver's name : %s\n",a[i].num,a[i].money,a[i].name);
   printf("\t Starting time : %-6s\t End time : %-6s\t The total number of the platform : %d\n",a[i].topen,a[i].tclose,a[i].n);
   printf("\t Bus routes :(1) %s",a[i].b[0].c);
   for(j=1;j<a[i].n;j++)
    printf(" ---->(%d) %s",j+1,a[i].b[j].c);
   printf("\n\n");
   }
  }
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n");
  printf("\t It's all displayed !!!\n");
  if(m==0)
   printf("\n\t No buses start at this station \n");
  break;
  }
 case '2':
  {
  printf(" Please enter the name of the terminating platform you want to query :\n");
  scanf("%s",cc);
  printf("\n In order to %s Buses for terminating the platform are as follows :\n",cc);
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
  for(i=0;*a[i].num!='\0'&&i<N;i++)
  {
   k=a[i].n;
   if(strcmp(a[i].b[k-1].c,cc)==0)
   {
   m=1;
   printf("\n");
   printf("\t Route number : %-6s\t One-way fares : %d  yuan \t\t The driver's name : %s\n",a[i].num,a[i].money,a[i].name);
   printf("\t Starting time : %-6s\t End time : %-6s\t The total number of the platform : %d\n",a[i].topen,a[i].tclose,a[i].n);
   printf("\t Bus routes :(1) %s",a[i].b[0].c);
   for(j=1;j<a[i].n;j++)
    printf(" ---->(%d) %s",j+1,a[i].b[j].c);
   printf("\n\n");
   }
  }
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n");
  printf("\t It's all displayed !!!\n");
  if(m==0)
   printf("\n\t No buses start at this station \n");
  break;
  }
 case '3':
  {
  printf(" Please enter the name of the channel you want to query :\n");
  scanf("%s",cc);
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n");
  for(i=0;*a[i].num!='\0'&&i<N;i++)
   for(k=1;k<a[i].n-1;k++)
   if(strcmp(a[i].b[k].c,cc)==0)
   {
    m=1;
    printf("\n");
    printf("\t Route number : %-6s\t One-way fares : %d  yuan \t\t The driver's name : %s\n",a[i].num,a[i].money,a[i].name);
    printf("\t Starting time : %-6s\t End time : %-6s\t The total number of the platform : %d\n",a[i].topen,a[i].tclose,a[i].n);
    printf("\t Bus routes :(1) %s",a[i].b[0].c);
    for(j=1;j<a[i].n;j++)
    printf(" ---->(%d) %s",j+1,a[i].b[j].c);
    printf("\n\n");
   }
  printf("\n- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n");
  printf("\t It's all displayed !!!\n");
  if(m==0)
   printf("\n\t No buses use the station as a platform \n");
  break;
  }
 case '4':
  {
  printf("\n\t\t Press enter to return to the query menu \n");
  fflush(stdin);              // Clear keyboard buffer 
  getchar();
  system("cls");
  return;              // Go back to the main menu 
  }
 fflush(stdin);              // Clear keyboard buffer 
 getchar();
 system("cls");
 }
 }
 return;
}
 
void save()     // Information saving function  
{
 FILE *fp=NULL;
 int i;
 if((fp=fopen("bus.txt","w+"))==NULL)      // Open the name as read and write "bus" Text file of 
 {
 printf(" File opening error !!!\n");
 return;
 }
 fp=fopen("bus.txt","w+");
 for(i=0;*a[i].num!='\0'&&i<N;i++)          // Output data from memory to disk 
 if(fwrite(&a[i],sizeof(struct bus),1,fp)!=1)
  break;
 printf("\n\t Save success !!!\n");
 fclose(fp);
 return;
}
 
void mainmeun() // The main menu 
{
 printf("\n\t\t         The main menu ");
 printf("\n\t\t****************************************");
 printf("\n\t\t*      1 , information entry         *");
 printf("\n\t\t*      2 , information display         *");
 printf("\n\t\t*      3 , information modification         *");
 printf("\n\t\t*      4 , information deletion         *");
 printf("\n\t\t*      5 , information query         *");
 printf("\n\t\t*      6 , quit the system         *");
 printf("\n\t\t****************************************");
 printf("\n\n\t\t\t Please enter your choice :");
}
 
// Menu input detection function 
char Test(char a,char b,char c)
{
 while(a<b||a>c)
 {
 printf("\n\t\t\t Input error, please retype : ");
 fflush(stdin);              // Clear keyboard buffer 
 a=getchar();
 }
 return a;
}

For more information, please pay attention to the topic management System Development.


Related articles: