24小时热门版块排行榜    

查看: 2598  |  回复: 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的回帖

holmescn

金虫 (正式写手)

引用回帖:
Originally posted by 好好努力 at 2011-05-07 16:38:02:
VC6.0就那么垃圾吗?
不过,明明在dev c++能运行的那个,在vc6偏偏就不行,想不明白

倒退十年,打死我也不敢说VC6不好啊。可这都快2012了,怎么还用VC6啊,而且还用VC6编译谭的代码。
9楼2011-05-07 21:55: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的回帖
信息提示
请填处理意见