| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1487 人关注过本帖, 2 人收藏
标题:我照书打了这个程序,怎么有错误?谭浩强,张基温编的C书本~
只看楼主 加入收藏
小小
Rank: 1
等 级:新手上路
威 望:1
帖 子:219
专家分:0
注 册:2004-5-31
收藏(2)
 问题点数:0 回复次数:6 
我照书打了这个程序,怎么有错误?谭浩强,张基温编的C书本~
用链表存放学生数据: #include"stdlib.h" #include"stdio.h" struct stud {char name[20]; long num; int age; char sex; float score; struct stud *next; }; struct stud *head, *this, *new; main() {char ch; int flag=1; head=NULL; while(flag) {printf("\ntype'E'or'e'to enter new record,"); printf("\ntype'L'or'l'to list all records:"); ch=getchar();getchar(); switch(ch) { case'e': case'E':new_record();break; case'l': case'L':listall();break; default:flag=0;} } } void new_record(void) { int numstr[20]; new=(struct stud *) malloc (sizeof (struct stud)); if(head==NULL) head=new; else {this=head; while (this->next!=NULL) this=this->next; this->next=new; } this=new; printf("\nenter name:"); gets(this->name); printf("\nenter number:"); gets(numstr); this->num=atol(numstr); printf("\nenter age:"); gets(numstr); this->age=atoi(numstr); printf("\nenter sex:"); this->sex=getchar();getchar(); printf("\nenter score:"); gets (numstr); this->next=NULL; } void listall(void) {int i=0; if(head==NULL) {printf("\nempty list. \n");return;} this=head; do{ printf("\nrecord number %d\n",++i); printf("name:%s\n",this->name); printf("num:%ld\n",this->num); printf("age:%d\n",this->age); printf("sex:%c\n",this->sex); printf("score:%6.2f\n",this->score); this=this->next; } while(this!=NULL); } 朋友们帮我看看~~ turboc 2.0编译文件http://wenmin311.go.nease.net/wenmin.rar

[此贴子已经被作者于2004-06-02 12:12:47编辑过]

搜索更多相关主题的帖子: 谭浩强 张基温 书本 stud 
2004-06-02 12:10
zff_ff
Rank: 1
等 级:新手上路
帖 子:147
专家分:0
注 册:2004-5-12
收藏
得分:0 

没仔细看程序

struct stud *head, *this, *new;

你确定这句是书上的原话吗?

this 还有 new可以当变量?


偶是一只想要飞却忘了咋飞的菜鸟
2004-06-02 15:14
小小
Rank: 1
等 级:新手上路
威 望:1
帖 子:219
专家分:0
注 册:2004-5-31
收藏
得分:0 

书上是这样的哦

这本书好象错误满多的~~

书名是:

高等学校计算机基础教材系列

C语言

程序设计教程

( 第二版)

谭浩强 张基温 唐永炎 编著


有一天咖啡的舞者 £
2004-06-02 18:35
小小
Rank: 1
等 级:新手上路
威 望:1
帖 子:219
专家分:0
注 册:2004-5-31
收藏
得分:0 
倒霉鬼 好热心 谢谢呀~

有一天咖啡的舞者 £
2004-06-02 18:41
zff_ff
Rank: 1
等 级:新手上路
帖 子:147
专家分:0
注 册:2004-5-12
收藏
得分:0 
以下是引用小小在2004-06-02 18:41:33的发言: 倒霉鬼 好热心 谢谢呀~

偶叫倒霉鬼3哩

把程序放在纯c编译器里编译,在C++环境里是肯定无法通过的

以谭浩强的名声,写的书应该不是那么差

[此贴子已经被作者于2004-06-02 20:05:30编辑过]


偶是一只想要飞却忘了咋飞的菜鸟
2004-06-02 20:04
小小
Rank: 1
等 级:新手上路
威 望:1
帖 子:219
专家分:0
注 册:2004-5-31
收藏
得分:0 

是的啊,我是放在纯C编译器里的;

那书我想只是借浩强的名声,是基温写的!~~哎!!

这书里不只这个,长点的程序好几个都不能通过。

倒霉鬼为什么+3??

现在就读哪里啊?


有一天咖啡的舞者 £
2004-06-03 19:55
c
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2004-6-9
收藏
得分:0 

你在最前面加上一句 #include "stdarg.h",这句可能不是必须的,但在有的地方要

再在main()前面加上 viod new_record(void); viod listall(void); 或把这两个函数移到main()的前就行了

改了后在我的系统上可以运行


有志同道合者请加群:12133884 联系:Sonic.hu@
2004-06-09 23:12
快速回复:我照书打了这个程序,怎么有错误?谭浩强,张基温编的C书本~
数据加载中...
 
   



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

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