怎么把输入的通讯录导入到txt
程序代码:
#include"stdio.h" #include"stdlib.h" #include"string.h" struct student { int no; /*学号*/ char name[20]; /*姓名*/ char acdamic[20]; /*院系*/ char major[20]; /*专业*/ char province[20]; /*籍贯*/ char address[40]; /*家庭地址*/ long phone; /*联系电话*/ struct student *next; }; struct student *input(); void print(struct student *h); struct student *insert(struct student *h); struct student *del(struct student *h); void find4(struct student *h); void find3(struct student *h); void find2(struct student *h); void find1(struct student *h); struct student *head=NULL; char ch,*menu[]={"------------------通讯录菜单---------------", "1.----------建立学生通讯录-----------------", "2.----------输出全部学生通讯录-------------", "3.----------增加的学生的个数---------------", "4.----------删除指定学号的学生-------------", "5.----------按系别查找学生信息-------------", "6.----------按专业查找学生信息-------------", "7.----------按姓名查找学生信息-------------", "8.----------按学号查找学生信息-------------", "9.----------退出通讯录---------------------"}; struct student *input() /*输入函数*/ { int n; printf("请输入你要建立的学生通讯录的学生个数:\n"); scanf("%d",&n); struct student *h=NULL,*p,*q; int i; for(i=1;i<=n;i++) { printf("请依次输入第%d个学生的学号,姓名,系别,专业,籍贯,家庭住址和联系电话:\n",i); p=(struct student *)malloc(sizeof(struct student)); if(p==NULL) { printf("内存不足!\n"); exit(0); } scanf("%d%s%s%s%s%s%ld",&p->no,p->name,p->acdamic,p->major,p->province,p->address,&p->phone); if(i==1)h=p; else q->next=p; q=p; } q->next=NULL; return h; } void print(struct student *h) /*输出函数*/ { struct student *p=h; while(p) { printf("学生信息:\n%d,%s,%s,%s,%s,%s,%ld\n",p->no,p->name,p->acdamic,p->major,p->province,p->address,p->phone); p=p->next; } } struct student *insert(struct student *h) /*增加学生信息*/ { int n; printf("请输入你要增加的学生的个数:\n"); scanf("%d",&n); struct student *p,*r; int i; for(i=1;i<=n;i++) { r=(struct student *)malloc(sizeof(struct student)); printf("请输入第%d个你要插入的学生的信息:\n",i); scanf("%d%s%s%s%s%s%ld",&r->no,r->name,r->acdamic,r->major,r->province,r->address,&r->phone); p=h; h=r; r->next=p; } return h; } struct student *del(struct student *h) /*按学号进行删除*/ { int n; printf("请输入要删除的学生的学号:\n"); scanf("%d",&n); struct student *p,*q; if(h=NULL)printf("empty list!\n"); else { p=h; while(p->no!=n&&p->next) {q=p;p=p->next;} if(p->no==n) { if(h==p)h=p->next; else q->next=p->next; } else printf("%d is not found!\n"); } return h; } void find1(struct student *h) /*按院系查找学生信息*/ { char s[40]; printf("请输入要查找的学生的院系:\n"); scanf("%s",s); struct student *p; if(h==NULL)printf("empty list!\n"); else { p=h; while(p) { if(strcmp(p->acdamic,s)==0) printf("学生信息:\n%d %s %s %s %s %s %ld\n",p->no,p->name,p->acdamic,p->major,p->province,p->address,p->phone); p=p->next; } } } void find2(struct student *h) /*按专业查找*/ { char s[20]; printf("请输入要查找的学生的专业名:\n"); scanf("%s",s); struct student *p; if(h==NULL)printf("empty list!\n"); else { p=h; while(p) { if(strcmp(p->major,s)==0) printf("学生信息:\n%d %s %s %s %s %s %ld\n",p->no,p->name,p->acdamic,p->major,p->province,p->address,p->phone); p=p->next; } } } void find3(struct student *h) /*按姓名查找*/ { char ss[10]; printf("请输入要查找的学生的姓名:\n"); scanf("%s",ss); struct student *p; if(h==NULL)printf("empty list!\n"); else { p=h; while(p) { if(strcmp(p->name,ss)==0) printf("学生信息:\n%d %s %s %s %s %s %ld\n",p->no,p->name,p->acdamic,p->major,p->province,p->address,p->phone); p=p->next; } } } void find4(struct student *h) /*按学号查找*/ { int num; printf("请输入要查找的学生的学号:\n"); scanf("%d",&num); struct student *p; if(h==NULL)printf("empty list!\n"); else { p=h; while(p) { if(p->no==num) printf("学生信息:\n%d %s %s %s %s %s %ld\n",p->no,p->name,p->acdamic,p->major,p->province,p->address,p->phone); else printf("没有你要查找的学生信息!\n"); p=p->next; } } } int menu_select() { int i,s; char c[3]; for(i=0;i<10;i++) printf("%s\n",menu[i]); do { scanf("%s",c); s=atoi(c); }while(s<0||s>9); return s; } main() { for(;;) { switch(menu_select()) { case 1:head=input();break; case 2:print(head);break; case 3:head=insert(head);break; case 4:head=del(head);break; case 5:find1(head);break; case 6:find2(head);break; case 7:find3(head);break; case 8:find4(head);break; case 9:exit(0); } } }
求教