为什么这个C语言编的通讯录在VC运行出错?
#include "stdio.h"#include "stdlib.h"#include "string.h"struct student{ int no;//学号 char name[20];//姓名 char acdamic[20];//院系 char maj... 展开
#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->maior,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->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("学生信息:\,%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);} }} 收起
其他答案
基本上都是拼写错误,个别不是。你按照VC的提示逐个改就可以啊,一下正解====================================#include "stdio.h"#include "stdlib.h"#include "string.h"struct student { int no;//学号 char name[2 展开
基本上都是拼写错误,个别不是。你按照VC的提示逐个改就可以啊,一下正解====================================#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;struct student*h=NULL,*p,*q;int i;printf("请输入你要建立的学生同学录的学生个数:\n");scanf("%d",&n);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->phone);p=p->next;} } struct student*insert(struct student*h)//增加学生信息 { int n;struct student *p,*r;int i;printf("你要增加的学生的个数:\n");scanf("%d",&n);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;struct student*p,*q;printf("请输入你要删除的学生的学号:\n");scanf("%d",&n);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];struct student*p;printf("请输入要查找学生的院系:\n");scanf("%s",s);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];struct student*p;printf("请输入要查找的学生的专业名:\n");scanf("%s",s);if(h==NULL) printf("empty list!\n");else { p=h;while(p) { if(strcmp(p->major,s)==0) printf("学生信息:\,%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];struct student *p;printf("请输入要查找的学生的姓名:\n");scanf("%s",ss);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;struct student *p;printf("请输入要查找的学生的学号:\n");scanf("%d",&num);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);} } } 收起
2011-01-25 04:17
来自北京市
评论(0)赞(0)点赞赞(0)
发布评论
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。
相关知识
- 38浏览小区旧楼加装电梯使用期间问题频出,如何保障电梯安全运行?
- 46浏览盛福片区地块C怎么样 盛福片区地块C房价
- 34浏览天目医药港单元ZX11-C-17地块怎么样 天目医药港单元ZX11-C-17地块地址
- 17浏览锦绣水居二期C区怎么样 锦绣水居二期C区电话
- 24浏览中天豪庭C区怎么样 中天豪庭C区房价走势
- 25浏览保利国际城翡丽湾C区怎么样 保利国际城翡丽湾C区地址
- 55浏览沣西新城创新港C板块CXG东北七路以东怎么样 沣西新城创新港C板块CXG东北七路以东地址
- 12浏览金石滩北部区C-45-1宗地怎么样 金石滩北部区C-45-1宗地电话
- 46浏览两江新区两路组团C、F标准分区C03-2怎么样 两江新区两路组团C、F标准分区C03-2多少钱
- 74浏览九龙坡区西彭组团C分区C3-3-2/08怎么样 九龙坡区西彭组团C分区C3-3-2/08价格
- 69浏览永盛花苑三期C区怎么样 永盛花苑三期C区电话
- 25浏览泉城花都C区东侧地块怎么样 泉城花都C区东侧地块房价
- 56浏览柳新矿定销房C地块怎么样 柳新矿定销房C地块价格
- 23浏览江北区江北市场园区5-c-1地块怎么样 江北区江北市场园区5-c-1地块是哪个开发商
- 13浏览高新区西永组团C分区C11-17-2/05地块怎么样 高新区西永组团C分区C11-17-2/05地块房价走势
- 21浏览金石滩北部区C-46宗地怎么样 金石滩北部区C-46宗地是哪个开发商
- 130浏览澄地2021-C-23怎么样 澄地2021-C-23地址
- 15浏览崇贤新城陆家桥C-1-2地块怎么样 崇贤新城陆家桥C-1-2地块二手房出售
- 209浏览中关村国家工程技术创新基地C-30地块怎么样 中关村国家工程技术创新基地C-30地块房价走势
![](http://static.soufunimg.com/ggcp/asknodejs/online/images/icon_success.png)
回答成功