| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 830 人关注过本帖
标题:这个问题有点晕,请高手指教
只看楼主 加入收藏
lp520zw
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-4-23
收藏
 问题点数:0 回复次数:5 
这个问题有点晕,请高手指教
//学生系统(引用&附加头结点) //预定义 #include<iostream.h> #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<malloc.h> #define NULL 0 #define LEN sizeof(struct student) //存储结构 struct student{ long num;//学号 char name[20];//姓名 float English,Math,Computer;//各科成绩 struct student *next;//指针域 }; int n; //基本操作 struct student *creat(void){ //创建链表 struct student *head; struct student *p1,*p2; n=0; p1=p2 =(struct student *)malloc(LEN); scanf("%ld,%10s,%f,%f,%f",&p1->num,p1->name,&p1->English,&p1->Math,&p1->Computer); head=NULL; while(p1->num!=0){ n=n+1; if(n==1)head=p1; else p2->next=p1; p2=p1; p1=(struct student *)malloc(LEN); scanf("%ld,%10s,%f,%f,%f",&p1->num,p1->name,&p1->English,&p1->Math,&p1->Computer); } p2->next=NULL; return(head); } void print(struct student *head){ //输出 struct student *p; printf("\nNOW,These %d recordes are:\n",n); printf("num\t\tname\tEnglish\tMath\tComputer"); p=head; if(head!=NULL) while(p!=NULL) {printf("\n%ld\t%10s\t%f\t%f\t%f\n",p->num,p->name,p->English,p->Math,p->Computer); p=p->next; } } void main(){ clrscr();//清屏 struct student *head,stu; long del_num; printf("input records:"); head=creat(); print(head); printf("\ninput the deleted number:"); getch();//暂停 } 以上是我作的关于学生系统的程序(链表). 我的测试结果显示太不美观,并且我觉的还有一点错误 在name之后的数据有问题, 请指教,谢谢.
搜索更多相关主题的帖子: 指教 
2005-05-23 03:24
lp520zw
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-4-23
收藏
得分:0 
能不能在加一些功能!比如说作一个选择菜单??
2005-05-23 03:26
激情依旧
Rank: 1
等 级:新手上路
威 望:2
帖 子:524
专家分:0
注 册:2005-4-4
收藏
得分:0 
兄弟努力哟!! 不知道怎么说你的。。。你的宏定义太多了。让人看了就头晕。我帮你删除一些。根本没必要#define NULL 0 还有为了程序可读性更好不要偷懒 #define sizeof(Node) LEN 这样很多会看了莫名其妙。还有你的清屏函数。我不知道有什么用。我帮你屏蔽了。我帮你调试好了。并且带有抓图。你看看我的抓图.强烈建议。你把0做为结束标记。你应该声明一下。光标一直闪。运行你程序的根本就不知道做什么好。紧记一点。程序是写给人家看的。不是只自己看的。你拿我程序上机看看。 #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<malloc.h> typedef struct student{ long num;//学号 char name[20];//姓名 float English,Math,Computer;//各科成绩 struct student *next;//指针域 }Node; int n; //基本操作 Node *creat(void) { //创建链表 Node *head; Node *p1,*p2; n=0; p1=p2 =(Node *)malloc(sizeof(Node)); scanf("%ld%s%f%f%f",&p1->num,p1->name,&p1->English,&p1->Math,&p1->Computer); head=NULL; while(p1->num!=0) { n=n+1; if(n==1)head=p1; else p2->next=p1; p2=p1; p1=(Node*)malloc(sizeof(Node)); scanf("%ld,%10s,%f,%f,%f",&p1->num,p1->name,&p1->English,&p1->Math,&p1->Computer); } p2->next=NULL; return(head); } void print(Node *head){ //输出 Node *p; printf("\nNOW,These %d recordes are:\n",n); printf("num\t\tname\tEnglish\tMath\tComputer"); p=head; if(head!=NULL) while(p!=NULL) {printf("\n%ld\t%10s\t%f\t%f\t%f\n",p->num,p->name,p->English,p->Math,p->Computer); p=p->next; } } void main(){ //clrscr();//清屏 Node *head,stu; long del_num; printf("input records:"); head=creat(); print(head); printf("\ninput the deleted number:"); getch();//暂停 }
图片附件: 游客没有浏览图片的权限,请 登录注册

生是编程人!!!!死是编程鬼!!!!颠峰人生!!!焚尽编程!!! 爱已严重死机!情必须重新启动!情人已和服务器断开连接!网恋也需要重新拨号!-----激情依旧
2005-05-23 08:13
lp520zw
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-4-23
收藏
得分:0 
我才学C,没有多久,谢谢你的批导!
我会努力的
2005-05-25 04:53
激情依旧
Rank: 1
等 级:新手上路
威 望:2
帖 子:524
专家分:0
注 册:2005-4-4
收藏
得分:0 
   c 非常重要。要学好它。很多人说他过时了。那是他们不懂c的用处。做单片机的人就是用c的。那些人工资很高。不过到是挺枯燥的。学好c后学其他东西就快。兄弟努力点吧!

生是编程人!!!!死是编程鬼!!!!颠峰人生!!!焚尽编程!!! 爱已严重死机!情必须重新启动!情人已和服务器断开连接!网恋也需要重新拨号!-----激情依旧
2005-05-25 07:27
lp520zw
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2005-4-23
收藏
得分:0 
我知道了,谢了,兄弟
2005-05-27 01:22
快速回复:这个问题有点晕,请高手指教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018064 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved