24小时热门版块排行榜    

查看: 3180  |  回复: 12
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

好好努力

金虫 (正式写手)

[求助] 谭浩强C语言教材,P298页照着输入都不对!求原因

#include
#include
#define NULL 0
#define LEN sizeof(struct student)

struct student
{
        long num;
        float score;
        struct student *next;


};
int n;
struct student *creat(void)
{
   struct student *head,*p1,*p2;
   n=0;
   p1=p2=(struct student *)malloc(LEN);
   scanf("%ld%f",&p1->num,&p1->score);
   head=NULL;
   while(p1->num!=0)
   {
           n++;
           if(n==1)   head=p1;
           else   p2->next=p1;
           p2=p1;
           p1=(struct student *)malloc(LEN);
           scanf("%ld%f",&p1->num,&p1->score);
   
   
   
   
   }

  p2->next=NULL;
  return head;



}

void main()
{
  struct student *lin1=creat();

}

//scanf("%ld%f",&p1->num,&p1->score);好像是这一句出错,但是将float score改成int score就不会出错了,下面的%f相应的改成%d就没错了!真搞不懂了,望高手赐教!
回复此楼
好好就好!!!
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

好好努力

金虫 (正式写手)

引用回帖:
Originally posted by holmescn at 2011-05-07 08:43:26:
LZ也没说是什么编译器,难道又是VC6?

我用的是VC6.0编译的,那个程序昨晚上看了一楼的回复,也没做修改 啊。后来我又运行了下,居然可以了!!
     但是我将可以运行的代码复制到另外一个文件中,编译运行还是像以前一样,出现那个“Debug error”"runtime error"真搞不明白了。但是我刚才安装一个DEV C++居然又没有上面说的那种错误!!
     从昨天开始就纠结在这儿
   这个截图是VC6.0出错的截图

好好就好!!!
6楼2011-05-07 11:11:51
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 13 个回答

libralibra

至尊木虫 (著名写手)

骠骑将军

【答案】应助回帖

★ ★ ★ ★ ★
微尘、梦想(金币+5): 谢谢参与应助! 2011-05-06 19:50:24
好好努力(金币+1): 2011-05-06 23:31:55
dev-c++4.9 编译通过,毫无问题,
#define NULL 0这句不需要,但是使用float没有错误
CODE:
#include
#include

#define LEN sizeof(struct student)

struct student
{
        long num;
        float score;
        struct student *next;


};
int n;
struct student *creat(void)
{
   struct student *head,*p1,*p2;
   n=0;
   p1=p2=(struct student *)malloc(LEN);
   printf("Please input num and score:");
   scanf("%ld%f",&p1->num,&p1->score);
   printf("%d,%f\n",p1->num,p1->score);

   head=NULL;
   while(p1->num!=0)
   {
           n++;
           if(n==1)   head=p1;
           else   p2->next=p1;
           p2=p1;
           p1=(struct student *)malloc(LEN);
           printf("Please input num and score:");
           scanf("%ld%f",&p1->num,&p1->score);
           printf("%d,%f\n",p1->num,p1->score);
           //printf("%f\n",fabs(p1->num));
   
   }

  p2->next=NULL;
  return head;



}

int main(int args, char* argv[])
{
  struct student *lin1=creat();
  
  system("PAUSE");
  return 0;

}

结果
matlab/VB/python/c++/Java写程序请发QQ邮件:790404545@qq.com
2楼2011-05-06 16:36:12
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

yalefield

金虫 (文坛精英)

老汉一枚

【答案】应助回帖

★ ★
微尘、梦想(金币+2): 谢谢回复! 2011-05-07 21:34:33
好好努力(金币+4): 2011-05-10 18:06:39
scanf能不能读入浮点数,那不是C语言的事,而是编译器和库的事。
有的开发环境,默认编译条件,就带有浮点处理,那就没事。
如果默认的编译条件不带浮点处理,那就出错。
3楼2011-05-06 22:37:45
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

holmescn

金虫 (正式写手)

LZ也没说是什么编译器,难道又是VC6?
4楼2011-05-07 08:43:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 投票:  有多少人是今天查系统知道结果的? +16 爱看书的可乐 2026-08-26 18/900 2026-08-28 17:09 by winsaint
[基金申请] 有没有仍没收到信息的 +3 德尚中行 2026-08-27 3/150 2026-08-28 15:24 by rongshuxia
[教师之家] 导师吐槽:我怎么摊上了这么个极品研究生! +8 苏东坡二世 2026-08-23 8/400 2026-08-28 14:41 by lkforward
[基金申请] 麻烦专家们看看评委们的意见(F口面上) +4 gdd2018 2026-08-28 9/450 2026-08-28 14:22 by jklily
[基金申请] 基金系统什么内容也没有 30+4 winsaint 2026-08-27 9/450 2026-08-28 11:06 by maolC
[基金申请] 基金未中,这种答复是模板吗? +5 zhaosm1982 2026-08-27 6/300 2026-08-27 16:00 by lfy8008
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +5 a089 2026-08-26 6/300 2026-08-27 14:05 by jonewore
[基金申请] 怎么看青基中了没有啊 +5 叶九微 2026-08-26 5/250 2026-08-27 10:35 by l_zh2008
[文学芳草园] 梦想 +3 myrtle 2026-08-26 3/150 2026-08-27 10:01 by angelyueyi
[基金申请] 我不理解! +15 Edward_pc 2026-08-26 23/1150 2026-08-26 20:34 by zzuzxg
[基金申请] 2026年的国家社科基金项目通讯评审的新规则与新动向、新挑战 +7 process2012 2026-08-23 10/500 2026-08-26 19:23 by hmhminy
[基金申请] 范进中举一文的中心思想 +9 炎黄贵胄 2026-08-22 10/500 2026-08-26 15:40 by semaglutide
[基金申请] 能否退出参与的面上项目解除限项 +23 koalala 2026-08-24 26/1300 2026-08-26 14:29 by 宝贝虫子
[基金申请] 国际合作可查了,中了面上 (EPI+1)(金币+50) +18 Ldrop2023 2026-08-26 18/900 2026-08-26 11:15 by cmrandy
[基金申请] 系统进不去 +4 yanglien 2026-08-26 5/250 2026-08-26 11:10 by wenfengw83
[基金申请] 项目信息和经费信息在系统里都可以看到了 +6 wittyboy 2026-08-26 14/700 2026-08-26 10:55 by wittyboy
[基金申请] 国合可查了 +3 paperzjh 2026-08-26 3/150 2026-08-26 10:41 by LemmonTr
[基金申请] 在坚冰还盖着北海的时候,我看到了怒放的梅花。 (金币+10) +6 ziyangfang 2026-08-25 9/450 2026-08-25 20:26 by huagongfeihu
[基金申请] 某些机构,以效率低为荣,以效率低作为存在感 +9 yuleib84 2026-08-25 10/500 2026-08-25 17:14 by alexon
[基金申请] 如果此刻你正在为国基感到焦虑,不妨来听听这首《基金之外》 +8 scalable 2026-08-24 8/400 2026-08-25 12:52 by jnhyjjm
信息提示
请填处理意见