#include
#include
Struct data {//statement structure
Char province [20].//province
Char city [20].//city
Int count;//the number of
};
Int main (int arg c, char * argv [])
{
int i=0;
int count=0;
The FILE * fp=NULL;//write file
Struct data d [140];
Char [20] p;//the current province
If (arg c!
=4){
return 1;
}
Fp=fopen (argv [1], the "r");//temporarily open the specified file
if (! Fp)
{
Printf (" failed to open the file! \n");//failed to open the file
}
While (1)//read files in the structure array
{
If (fscanf (fp, "% s \ \ t t % s % d", & amp; D [I]. Province, & amp; D [I] city, & amp; D [I]. Count)!=(EOF)
{
i++;
}
The else break;
}
The count=I;
The fclose (fp);
Fp=fopen (argv [2], "w");//temporarily open the specified file
if (! Fp)
{
Printf (" failed to open the file! \n");//failed to open the file
}
Strcpy (p, d [0]. Province);
If (STRCMP (province, the province)==0) break;
Fprintf (fp, "% s \ n", p);
Fprintf (fp, "% s \ n \ t % d", d [0]. City, d [0]. Count);
For (I=1; i
If (STRCMP (p, d [I] province)==0) fprintf (fp, "% s \ n \ t % d", d [I] city, d [I]. Count);
The else
{
Strcpy (p, d [I] province);
Fprintf (fp, "% s \ n \ n", p);
Fprintf (fp, "% s \ n \ t % d", d [I] city, d [I]. Count);
}
}
The fclose (fp);
return 0;
}