1、#include#include#includetypedef struct protectchar quhao7;char bianhao5;char yanghuren20;char riqi11;char cuosi20;char zuangkuang20;struct protect *prot_next;prot;typedef struct gushumingmuchar quhao7;char bianhao5;char name20;char xueming20;char kesu20;int shuling;char querensijian11;char baohujibi
2、e;char zaizididian30;struct protect *prot_head;struct gushumingmu *gusm_next;gusm;typedef struct chengquxinxichar quhao7;char quming20;char bumen30;char dizi30;char dianhua13;char fuzeren20;struct gushumingmu *gusm_head;struct chengquxinxi *chex_next;chex;chex *chex_head;void create_cross_list(chex
3、*);void create_gusm(gusm *,chex *);void create_prot(prot *prot_head,gusm *p_gusm);int load_cross_list(chex *chex_head);int save_cross_list(chex *chex_head);void trav_chex(void);void trav_gusm(gusm *);void trav_prot(prot *);void traverse_cross_list(chex *chex_head);void edit_cross_list(void);void cou
4、nt_cross_list(chex *chex_head);void modf_chex(chex *chex_head);void modf_gusm(chex *p);void modf_prot(chex *p);void delt_chex(chex *p);void delt_gusm(chex *p);void delt_prot(chex *p);void inst_chex(chex *p);void inst_gusm(chex *p);void inst_prot(chex *p);void count(void);int levl_qcot(char *,char);i
5、nt zhuk_qcot(char *,char *);int kind_qcot(char *,char *);void one_levl_cout(void);void one_zhuk_cout(void);void one_kind_cout(chex *P);void totl_levl_cout(chex *p);void totl_zhuk_cout(void);void totl_kind_cout(chex *p);void one_shul_cout(void);void totl_shul_cout(void);int shul_qcot(char *,int);main
6、()char ch,ch1;printf(“ * n“ * * * * *n“ * * * * * *n“ * * * * * * *n“ * * * * * * * n“ * * * * *n“n“ * * * * *n“ * * * * * * * *n“ * * * * * * * *n“ * * * * * * *n“ * * * * *n“n“);doprintf(“ *n“ * 1:input and creat the cross list. *n“ * *n“ * 2:save the cross list. *n“ * *n“ * 3:load the cross list.
7、 *n“ * *n“ * 4:traverse the cross list. *n“ * *n“ * 5:edit the cross list *n“ * *n“ * 6:count and sort the cross list *n“ * *n“ * 7:quit this program *n“ *n“);doprintf(“nttplease make a choice,(1-7)n“);ch=getchar();fflush(stdin);while(ch7);switch(ch)case 1:create_cross_list(break;case 2:save_cross_l
8、ist(chex_head);break;case 3:load_cross_list(break;case 4:traverse_cross_list(chex_head);break;case 5:edit_cross_list();break;case 6:count();break;case 7:printf(“tare you sure you have saved all the data and quit it?n“);ch1=getchar();fflush(stdin);if(ch1=y|ch1=Y)exit(-1);fflush(stdin);printf(“tContin
9、ue make a choice?yes or no?n“);ch=getchar();fflush(stdin);while( ch=y|ch=Y);void create_cross_list(chex *chex_head)chex *hp=NULL,*p_chex;char ch;loop: /*create chengqujinbenxinxi*/p_chex=(chex *)malloc(sizeof(chex);printf(“tPlease input information of the area:ntzip_code area_name department address
10、 phone charman:n“);scanf(“%s%s%s%s%s%s“,p_chex-quhao,p_chex-quming,p_chex-bumen,p_chex-dizi,p_chex-dianhua,p_chex-fuzeren);fflush(stdin);p_chex-gusm_head=NULL;p_chex-chex_next=hp;hp=p_chex;printf(“tContinue input information of the the area?yes or no?n“);ch=getchar();fflush(stdin);if(ch=y|ch=Y)goto
11、loop;(*chex_head)=hp;while(p_chex!=NULL) /*create information of ancient trees*/printf(“tCreate %ss ancient trees list?yes or no?n“,p_chex-quming);ch=getchar();fflush(stdin);if(ch=y|ch=Y)create_gusm(p_chex=p_chex-chex_next;void create_gusm(gusm *gusm_head,chex *p_chex)gusm *hp=NULL,*p_gusm;char ch;l
12、oop: /*create gusm*/p_gusm=(gusm *)malloc(sizeof(gusm);printf(“tPlease input %s new ancient trees information: ntsequence name science_name generic age confirm_time protect_level lacation:n“,p_chex-quming);scanf(“%s%s%s%s%d%s%1s%s“,p_gusm-bianhao,p_gusm-name,p_gusm-xueming,p_gusm-kesu,fflush(stdin);
13、strcpy(p_gusm-quhao,p_chex-quhao);p_gusm-prot_head=NULL;p_gusm-gusm_next=hp;hp=p_gusm;printf(“tContinue add ancient trees to %s?yes or no?n“,p_chex-quming);ch=getchar();fflush(stdin);if(ch=y|ch=Y) /*create prot*/goto loop;(*gusm_head)=hp;while(p_gusm!=NULL)printf(“tCreate %ss %ss protection history?
14、yes or no?n“,p_gusm-zaizididian,p_gusm-name);ch=getchar();fflush(stdin);if(ch=y|ch=Y)create_prot(p_gusm=p_gusm-gusm_next;void create_prot(prot *prot_head,gusm *p_gusm)prot *hp=NULL,*p_prot;char ch;loop: /*create gushuyanghuxinxi*/p_prot=(prot *)malloc(sizeof(prot);printf(“tPlease input the informati
15、one of the new protection history :ntguardian nurse_time(1991-03-25) measures health_conditionn“);scanf(“%s%s%s%s“,p_prot-yanghuren,p_prot-riqi,p_prot-cuosi,p_prot-zuangkuang);fflush(stdin);strcpy(p_prot-quhao,p_gusm-quhao);strcpy(p_prot-bianhao,p_gusm-bianhao);p_prot-prot_next=hp;hp=p_prot;printf(“
16、tContinue input this %s protection history?yes or no?n“,p_gusm-name);ch=getchar();fflush(stdin);if(ch=y|ch=Y)goto loop;(*prot_head)=hp;void trav_chex(void)chex *p_chex=chex_head;printf(“*n“);while(p_chex)printf(“t%-7s%-11s%-17s%-14s%-12s%-6sn“,p_chex-quhao,p_chex-quming,p_chex-bumen,p_chex-dizi,p_ch
17、ex-dianhua,p_chex-fuzeren);p_chex=p_chex-chex_next;printf(“_n“);void trav_gusm(gusm *p_gusm)printf(“_n“);while(p_gusm)printf(“t%-12s%-20s%-20s%-15sntt %-8d%-15s%-5c%sn“,p_gusm-bianhao,p_gusm-name,p_gusm-xueming,p_gusm-kesu,p_gusm-shuling,p_gusm-querensijian,p_gusm-baohujibie,p_gusm-zaizididian);p_gu
18、sm=p_gusm-gusm_next;printf(“_n“);void trav_prot(prot *p_prot)printf(“_n“);while(p_prot)printf(“t%-8s%-7s%-11s%-14s%-15s%-15sn“,p_prot-quhao,p_prot-bianhao,p_prot-yanghuren,p_prot-riqi,p_prot-cuosi,p_prot-zuangkuang);p_prot=p_prot-prot_next;printf(“-n“);void traverse_cross_list(chex *chex_head)chex *
19、p_chex=chex_head;gusm *p_gusm=NULL;prot *p_prot=NULL;printf(“*n“);while(p_chex!=NULL) /*print out chengquxinxi*/printf(“the information or the area is:n%-10s%-15s%-15s%-12s%-15s%-18sn“,p_chex-quhao,p_chex-quming,p_chex-bumen,p_chex-dizi,p_chex-dianhua,p_chex-fuzeren);p_gusm=p_chex-gusm_head;while(p_
20、gusm!=NULL) /*printf out information of ancient trees*/printf(“-n“);printf(“%ss ancient trees information:n%-10s%-10s%-20s%-20s%-15snt %-10d%-20s%-20c%-30sn“,p_chex-quming,p_gusm-quhao,p_gusm-bianhao,p_gusm-name,p_gusm-xueming,p_gusm-kesu,p_gusm-shuling,p_gusm-querensijian,p_gusm-baohujibie,p_gusm-z
21、aizididian);p_prot=p_gusm-prot_head;while(p_prot!=NULL) /*printf out gushumingmuyanghuxinxi*/printf(“_n“);printf(“the protection history of this ancient tree:n%-8s%-7s%-15s%-12s%-15s%-15sn“,p_prot-quhao,p_prot-bianhao,p_prot-yanghuren,p_prot-riqi,p_prot-cuosi,p_prot-zuangkuang);p_prot=p_prot-prot_ne
22、xt;p_gusm=p_gusm-gusm_next;printf(“*n“);p_chex=p_chex-chex_next;int save_cross_list(chex *chex_head)FILE *out1,*out2,*out3;chex *p_chex=chex_head;gusm *p_gusm=NULL;prot *p_prot=NULL;if(out1=fopen(“e:chex.dat“,“wb“)=NULL) /*open out1*/printf(“tCant create a fill to save information of area.n“);return
23、(0);elseprintf(“tCreate fill chex.dat successfully!n“);if(out2=fopen(“e:gusm.dat“,“wb“)=NULL) /*open ou2*/printf(“tCant create a fill to save information of ancient trees.n“);return (0);elseprintf(“tCreate fill gusm.dat successfully!n“);if(out3=fopen(“e:prot.dat“,“wb“)=NULL) /*open ou3*/printf(“tCan
24、t create a fill to save information of protection.n“);return (0);elseprintf(“tCreate fill prot.dat successfully!n“);while(p_chex!=NULL) /*save in */fwrite(p_chex,sizeof(chex),1,out1);p_gusm=p_chex-gusm_head;while(p_gusm!=NULL)fwrite(p_gusm,sizeof(gusm),1,out2);p_prot=p_gusm-prot_head;while(p_prot!=N
25、ULL)fwrite(p_prot,sizeof(prot),1,out3);p_prot=p_prot-prot_next;p_gusm=p_gusm-gusm_next;p_chex=p_chex-chex_next;fclose(out1);fclose(out2);fclose(out3);printf(“t congrantulations! successfully saved!n“);return (-1);int load_cross_list(chex *chex_head)FILE *in1,*in2,*in3;chex *hp_chex=NULL,*p_chex;gusm
26、 *hp_gusm=NULL,*p_gusm;prot *p_prot;if(in1=fopen(“e:chex.dat“,“rb“)=NULL) /*open in1*/printf(“tFail to open fill chex.dat.ntpress any key to come back. n“);getchar();return(0);printf(“topen fill chex.dat successfully!n“);if(in2=fopen(“e:gusm.dat“,“rb“)=NULL) /*open in2*/printf(“tFail t open fill gus
27、m.dat.ntpress any key to come backn“);getchar();return(0);printf(“topen fill gusm.dat successfully!n“);if(in3=fopen(“e:prot.dat“,“rb“)=NULL) /*open in3*/printf(“tFail to open fill prot.dat.ntpress any key to came backn“);getchar();return(0);printf(“topen fill prot.dat successfully!n“);while(!feof(in
28、1) /*load chex*/p_chex=(chex *)malloc(sizeof(chex);fread(p_chex,sizeof(chex),1,in1);if(!feof(in1)p_chex-gusm_head=NULL;p_chex-chex_next=hp_chex;hp_chex=p_chex;(*chex_head)=hp_chex;while(!feof(in2) /*load gusm*/p_gusm=(gusm *)malloc(sizeof(gusm);fread(p_gusm,sizeof(gusm),1,in2);if(!feof(in2)p_chex=(*
29、chex_head);while(p_chex!=NULL)if(!strcmp(p_chex-quhao,p_gusm-quhao)p_gusm-prot_head=NULL;p_gusm-gusm_next=p_chex-gusm_head;p_chex-gusm_head=p_gusm;break;elsep_chex=p_chex-chex_next;while(!feof(in3) /*load prot*/p_prot=(prot *)malloc(sizeof(prot);fread(p_prot,sizeof(prot),1,in3);if(!feof(in3)p_chex=(
30、*chex_head);while(p_chex!=NULL)if(!strcmp(p_chex-quhao,p_prot-quhao)p_gusm=p_chex-gusm_head;while(p_gusm!=NULL)if(!strcmp(p_gusm-bianhao,p_prot-bianhao)p_prot-prot_next=p_gusm-prot_head;p_gusm-prot_head=p_prot;break;elsep_gusm=p_gusm-gusm_next;break;elsep_chex=p_chex-chex_next;fclose(in1);fclose(in2
31、);fclose(in3);printf(“tload succed!n“);return 1;void edit_cross_list(void)char ch;printf(“tt1:modifyn“tt2:deleten“tt3:insertn“);doprintf(“tplease make a choice:n“);ch=getchar();fflush(stdin);while(ch3);switch(ch)case 1:doprintf(“tt1:modify information of area.n“tt2:modify information of ancient tree
32、s.n“tt3:modify information of protection.n“);doprintf(“tplease make a choice:n“);ch=getchar();fflush(stdin);while(ch3);switch(ch)case 1:modf_chex(break;case 2:modf_gusm(break;case 3:modf_prot(break;printf(“tlifft back up one level to the previous menu,yes or no?n“);ch=getchar();fflush(stdin);while(c
33、h=y|ch=Y);break;case 2:doprintf(“tt1:delete information of area.n“tt2:delete information of ancient tree.n“tt3:delete information of protection.n“);doprintf(“tplease make a choice:n“);ch=getchar();fflush(stdin);while(ch3);switch(ch)case 1:delt_chex(break;case 2:delt_gusm(break;case 3:delt_prot(break
34、;printf(“tlifft back up one level to the previous menu,yes or no?n“);ch=getchar();fflush(stdin);while(ch=y|ch=Y);break;case 3:doprintf(“tt1:insert information of area.n“tt2:insert information of ancient trees.n“tt3:insert information of protection.n“);doprintf(“tplease make a choice:n“);ch=getchar()
35、;fflush(stdin);while(ch3);switch(ch)case 1:inst_chex(break;case 2:inst_gusm(break;case 3:inst_prot(break;printf(“tlifft back up one level to the previous menu,yes or no?n“);ch=getchar();fflush(stdin);while(ch=y|ch=Y);void modf_chex(chex *chex_head)chex *p_chex=NULL;char a20,ch;loop:p_chex=*chex_head
36、;printf(“tthe area list is :n“);trav_chex();printf(“tPlease input the areaname you want to modify.n“);scanf(“%s“,a);fflush(stdin);while(p_chex)if(!strcmp(p_chex-quming,a) break;p_chex=p_chex-chex_next;if(!p_chex)printf(“tYouve input an wrong areaname.n“);goto loop;lop:doprintf(“t1:%-20s2:%-20s3:%-20
37、snt4:%-20s5:%-20s6:%-20sn“,p_chex-quhao,p_chex-quming,p_chex-bumen,p_chex-dizi,p_chex-dianhua,p_chex-fuzeren);printf(“tplease choice the code number you want to modify.n“);ch=getchar();fflush(stdin);while(ch6|chquhao);break;case 2:scanf(“%s“,p_chex-quming);break;case 3:scanf(“%s“,p_chex-bumen);break
38、;case 4:scanf(“%s“,p_chex-dizi);break;case 5:scanf(“%s“,p_chex-dianhua);break;case 6:scanf(“%s“,p_chex-fuzeren);break;fflush(stdin);printf(“tpress 1 to continue modify this areas jibenxinxi.n“tpress 2 to modify othe areas jibenxinxi.n“tpress any other key to back to go on.n“);ch=getchar();fflush(std
39、in);switch(ch)case 1:goto lop;break;case 2:goto loop;break;void modf_gusm(chex *chex_head)chex *p_chex=NULL;gusm *p_gusm=NULL;char a20,b30,ch;loop:p_chex=*chex_head;printf(“tarea list is :n“);trav_chex();printf(“tPlease input the areaname where the ancient tree you want to modify is .n“);scanf(“%s“,a);fflush(stdin);while(p_chex)if(!strcmp(p_chex-quming,a) break;p_chex=p_chex-chex_next;/* while(strcmp(p_chex-quming,a) 此种循环有问题,若输错会卡死另外书上没有(p_chex) 这个判断条件,不懂是什么原理*/if(!p_chex)printf(“tYouve input an wrong areaname.n“);goto loop;lop:p_gusm=p_chex-gusm_head;printf(“tthis areas ancient tree li