24小时热门版块排行榜    

查看: 3174  |  回复: 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 16:26:09:
忘了VC6吧。如果你想学C/C++语言,那用DevC++就不错。如果需要工作,做开发,那就用VS2003 and later吧。

见我的帖子:珍爱生命,远离VC6, 及相关讨论。

VC6.0就那么垃圾吗?
不过,明明在dev c++能运行的那个,在vc6偏偏就不行,想不明白
好好就好!!!
8楼2011-05-07 16:38:02
已阅   回复此楼   关注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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 基金系统什么内容也没有 30+3 winsaint 2026-08-27 6/300 2026-08-28 01:46 by alongwaytogo
[基金申请] 国自然面上复盘~欢迎讨论 (金币+5) +11 晴天加油 2026-08-26 12/600 2026-08-28 01:22 by li09465290@
[基金申请] 为什么资助数各大高校都创新高,自己申请怎么就这么难 +9 Kittylucky 2026-08-27 9/450 2026-08-28 01:08 by jurkat.1640
[基金申请] 哪位高人中了,把查询到的截图贴出来让我看看,让我长长见识 +5 yuleib84 2026-08-26 6/300 2026-08-28 00:02 by yudaoqian88
[教师之家] 售SCI文章,我:8O5.5.1.O.54,科目齐全,可+急 +3 XLGfUIdOmEAO 2026-08-27 4/200 2026-08-27 22:26 by 3RAFyYXYSwGS
[基金申请] 基金未中,这种答复是模板吗? +5 zhaosm1982 2026-08-27 6/300 2026-08-27 16:00 by lfy8008
[基金申请] 怎么看青基中了没有啊 +5 叶九微 2026-08-26 5/250 2026-08-27 10:35 by l_zh2008
[基金申请] 为什么 国际(地区)合作与交流项目 没有放榜? 10+3 majunge000 2026-08-26 11/550 2026-08-27 08:42 by 北京莱茵编辑
[教师之家] 售SCI一区文章,我:8.O.551.O.5.4,科目全,可伽急 +3 LIbGuocjEEYw 2026-08-26 4/200 2026-08-27 04:33 by Ie9AyIAvGbvs
[硕博家园] 售SCI一区T0P文章,我:8.O.55.1.O.54,科目齐全,可+急 +3 LIbGuocjEEYw 2026-08-26 4/200 2026-08-27 02:01 by Ie9AyIAvGbvs
[基金申请] 我不理解! +15 Edward_pc 2026-08-26 23/1150 2026-08-26 20:34 by zzuzxg
[基金申请] 国际合作可查了,中了面上 (EPI+1)(金币+50) +18 Ldrop2023 2026-08-26 18/900 2026-08-26 11:15 by cmrandy
[基金申请] 今天务委会开完了,明天出结果吗 +19 angus9576 2026-08-25 23/1150 2026-08-26 10:03 by zp519
[基金申请] 国合现在查不到了吗? +10 chengyan1220 2026-08-24 20/1000 2026-08-26 08:57 by peasantsprig
[基金申请] 牛来!米来!面来! +8 beefly 2026-08-26 8/400 2026-08-26 08:37 by xuzhipiao
[基金申请] 明天应该可查了!? +6 chengyan1220 2026-08-23 6/300 2026-08-25 19:45 by zfd97
[基金申请] 某些机构,以效率低为荣,以效率低作为存在感 +9 yuleib84 2026-08-25 10/500 2026-08-25 17:14 by alexon
[基金申请] 没有任何消息-是不是就凉了 +9 图啦图啦 2026-08-24 10/500 2026-08-25 11:59 by 南海小哥
[基金申请] 人气不行了 +11 fansofjerry 2026-08-21 11/550 2026-08-25 11:04 by 孤独的英雄6
[基金申请] 建议基金发布提前给出明确的时间点 +13 kulium 2026-08-21 16/800 2026-08-24 16:27 by superceng
信息提示
请填处理意见