1、#include#include#include#includestruct kang char a20;char b20;char c20;char d50;struct kang *next;void zhang()printf(“);printf(“);printf(“);printf(“);struct kang* creat1(struct kang *p1)char a;struct kang *q;struct kang *p;q=p1;if(p1!=NULL)while(p1-next!=NULL)p1=p1-next;printf(“是否输入?(y or n)n“);scan
2、f(“%c“,while(a=y|a=Y)p=(struct kang *)malloc(sizeof(struct kang);printf(“请输入:n“);scanf(“%s“,p-a);printf(“请输入:n“);scanf(“%s“,p-b);printf(“请输入:n“);scanf(“%s“,p-c);printf(“请输入:n“);scanf(“%s“,p-d);p-next=NULL;if(p1=NULL)p1=p;q=p;elsep1-next=p;p1=p1-next;getchar();printf(“是否输入?(y or n)n“);scanf(“%c“,retu
3、rn q;void save(struct kang *p)FILE *fp;if(fp=fopen(“kang.txt“,“w“)=NULL)printf(“文件创建失败!n“);return;while(p!=NULL)fprintf(fp,“%s %s %s %s “,p-a,p-b,p-c,p-d);p=p-next;fclose(fp);struct kang *open()struct kang *pHead=NULL;struct kang *p=NULL;struct kang *temp=NULL;FILE *pfile=NULL;pfile=fopen(“kang.txt“
4、,“r“);int i=0;while(1)/创建一个节点temp=new struct kang;int flag=fscanf(pfile,“%s %s %s %s“,temp-a,temp-b,temp-c,temp-d);i+;/文件读取结束则返回 pHead *注意 不用 if(feof(pfile)if(flag=0)|(flag=-1)printf(“Read student from is secced!n“);return pHead;if(i=1)return NULL;temp-next=NULL;/假如是第一个节点if(p=NULL)p=temp;pHead=temp;printf(“pHead is finished!n“);/假如是第二个节点以上elsep-next=temp;p=p-next;p-next=NULL;fclose(pfile);void print(struct kang *p)while(p!=NULL)printf(“%s,%s,%s,%sn“,p-a,p-b,p-c,p-d);p=p-next;void main()struct kang *p,*p1;p=NULL;p=open();p=creat1(p);p1=p;print(p1);save(p);