Home > Back-end >  Can help to see where there is error?
Can help to see where there is error?

Time:10-22

#include
#include
#include
#include
# define N 100
Struct subway//define a structure
{
Char num [N].
Char line [N].//subway lines
Char sstation [N].//originating station
Char ostation [N].//the terminal
Char wstation [N].//way station number
Char charge [N].//ticket prices
} sub [N].//to play an alias sub structure;
Int k=1, n, m;
Char readfile ();//file read
Void the save ();//save to file the information
Void the insert ();//add subway information
Void the Delete ();//delete the subway information
Void the Search ();//query subway information
Void the Print (); Reading the subway information//
Void the Update ();//update the subway information
Void menu ();//main course monotonous with other function
Int main ()
{
While (k)
The menu ();
system("pause");
return 0;
}
Char readfile ()
{
The FILE * fp.//to read the file pointer
int i=0;//array mobile
If ((fp=fopen (" subway. TXT ", "r"))==NULL)//open operation is not successful
{
Printf (" the Open file is error!" );
system("pause");
The exit (0);
}
//the original TXT documents is a space between data, fscanf used to format the data in a read the file
While (fscanf (fp, "% s % s % s % s % s % s", sub num, sub [I] line, sub [I] sstation, sub [I] ostation, sub [I]. Charge, sub [I] wstation)==6)
{
i++;
}
fclose(fp);//close the file
N=I;
Printf (" input end! \n");
}
Void the save ()
{
int i;
The FILE * fp.//to read the file pointer
Fp=fopen (" subway. TXT ", "w");//open the file write operation
for(i=0; i{
//the original TXT documents is a space between data and fprintf paper used to format data
Fprintf (fp, "% s % s % s % s % s % s \ n", sub [I] num, sub [I] line, sub [I] sstation, sub [I] ostation, sub [I]. Charge, sub [I] wstation);
}
fclose(fp);//close the file
}
Void the insert ()/* * insert function/
{
The FILE * fp.//to read the file pointer
int i=0;//array mobile
If ((fp=fopen (" subway. TXT ", "r"))==NULL)//open operation is not successful
{
Printf (" the Open file is error!" );
system("pause");
The exit (0);
}
//the original TXT documents is a space between data, fscanf used to format the data in a read the file
While (fscanf (fp, "% s % s % s % s % s % s", sub [I] num, sub [I] line, sub [I] sstation, sub [I] ostation, sub [I]. Charge, sub [I] wstation)!=(EOF)
{
i++;
}
N=I;
Int j, flag;
Printf (" please input to increase the number of subway lines: \ n ");
The scanf (" % d ", & amp; m);
Do
{
flag=1;
While (flag)
{
Flag=0;
Printf (" please enter the first number: % d subway \ n ", I + 1);
The scanf (" % s ", sub [I] num);
for(j=0; jIf (STRCMP (sub [I] num, sub [j]. Journal of num)==0)
{
Printf (" the existing subway number, please check and re-enter! \n");
flag=1;
break;/* if there is any repeat immediately withdraw from the layer of circulation, improve the judge speed */
}
}
Printf (" please enter the first % d subway line 5: \ n ", I + 1);
The scanf (" % s ", sub [I] line);
Printf (" please enter the first subway originating station: % d \ n ", I + 1);
The scanf (" % s ", sub [I] sstation);
Printf (" please enter the first % d subway terminal \ n ", I + 1);
The scanf (" % s ", sub [I] ostation);
Printf (" please enter the first % d subway fares: \ n ", I + 1);
The scanf (" % s ", sub [I] charge);
Printf (" please enter the first % d is the route to the subway station number \ n ", I + 1);
The scanf (" % s ", sub [I] wstation);
If (flag==0)
{
i++;
}
}
While (iN +=m;
Printf (" input end! \ n \ n ");
fclose(fp);//close the file
system("pause");
Save ();//the function after adding information to save
return ;
}
Void the Delete ()
{
The FILE * fp.//to read the file pointer
int i=0;//array mobile
If ((fp=fopen (" subway. TXT ", "r"))==NULL)//open operation is not successful
{
Printf (" the Open file is error!" );
system("pause");
The exit (0);
}
//the original TXT documents is a space between data, fscanf used to format the data in a read the file
While (fscanf (fp, "% s % s % s % s % s % s", sub [I] num, sub [I] line, sub [I] sstation, sub [I] ostation, sub [I]. Charge, sub [I] wstation)!=(EOF)
{
i++;
}
N=I;
Int t, j, flag=0;
Char s1 [30];
Printf (" please enter a number: want to delete the subway \ n ");
The scanf (" % s ", s1);
for(t=0; tIf (STRCMP (sub [t] num, s1)==0)
{
flag=1;
For (j=t; jSub [t]=sub [t + 1);
}
If (flag==0)
Printf (" the number does not exist! \n");
If (flag==1)
{
Printf (" delete successful \ n ");
N -;
}
Save ();//the function delete information to save
}
Void the Search ()//find
{
The FILE * fp.//to read the file pointer
int i=0;//array mobile
If ((fp=fopen (" subway. TXT ", "r"))==NULL)//open operation is not successful
{
Printf (" the Open file is error!" );
system("pause");
The exit (0);
}
//the original TXT documents is a space between data, fscanf used to format the data in a read the file
While (fscanf (fp, "% s % s % s % s % s % s", sub [I] num, sub [I] line, sub [I] sstation, sub [I] ostation, sub [I]. Charge, sub [I] wstation)!=(EOF)
{
i++;
}
N=I;
Int j, item, flag=0;
Char s1 [10].
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1. According to the route query -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2. According to the originating station query -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3. According to the terminal query -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 4. Out of this menu -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- \ n ");
While (1)
{
Printf (" please select submenu number: ");
The scanf (" % d ", & amp; Item);
Flag=0;
The switch (item)
{
Case 1:
Printf (" please input to query subway lines: ");//by subway line search
The scanf (" % s ", s1);
for(j=0; jIf (STRCMP (sub [j]. J line, s1)==0)
{
flag=1;
Printf (" the number subway line originating station terminus fares via subway station number \ n ");
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related