The program was compiled normally,but catch below error while runing it.

oldhunter 2003-10-17 09:14:47
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
int num;
float score;
struct student *next;
};

main()
{
struct student *creat(void);
void print(struct student *);
struct student *p;
p = creat();
print(p);
}

struct student * creat(void)
{
struct student *head,*p1,*p2;
int n=0;
p1 = p2 = (struct student *) malloc(LEN);
scanf("%d,%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("%d,%f", &p1->num, &p1->score);
}

p2->next = NULL;

return head;
}

void print(struct student *p)
{
while(p != NULL)
{
printf("num: %d\tscore: %.2f\n", p->num, p->score);
p = (*p).next;
}
}


The program was compiled normally,but catch below error while runing it.

floating point formats not linked
Abnormal program termination.
...全文
57 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
oldhunter 2003-10-18
  • 打赏
  • 举报
回复
xiaosatan(傻蛋),you are right.I debug successfully.but this a strangly problem.
xiaosatan 2003-10-17
  • 打赏
  • 举报
回复
我想可以这样float temp=0.0;scanf("%f",&temp);p1->score=temp;
xiaosatan 2003-10-17
  • 打赏
  • 举报
回复
有人说是tc bug。但我想都是结构变量惹的祸。
oldhunter 2003-10-17
  • 打赏
  • 举报
回复
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
int num;
float score;
struct student *next;
};

main()
{
struct student *creat(void);
void print(struct student *);
struct student *p;
p = creat();
print(p);
}

struct student * creat(void)
{
struct student *head,*p1,*p2;
int n=0;
p1 = p2 = (struct student *) malloc(LEN);
scanf("%d", &p1->num);

printf("p1->num was pass.\n");

scanf("%f", &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("%d,%f", &(p1->num), &(p1->score));
}

p2->next = NULL;

return head;
}

void print(struct student *p)
{
while(p != NULL)
{
printf("num: %d\tscore: %.2f\n", p->num, p->score);
p = (*p).next;
}
}

It was print "p1->num was pass.",I make sure it hasn't error in line of "scanf("%d", &p1->num);",but it throw error in line of "scanf("%f", &p1->score);",why?

oldhunter 2003-10-17
  • 打赏
  • 举报
回复
To mmlymlymly(mly),If I enter ',' betwwen two number,it throw above error,else must enter number until enter ','.
To xiaosatan(傻蛋),I'll try...
darcymei 2003-10-17
  • 打赏
  • 举报
回复
there is no problem in your programe
i guess you forget to enter ','between you enter the data to the list
xiaosatan 2003-10-17
  • 打赏
  • 举报
回复
把scanf("%d,%f",&p1->num, &p1->num);改成scanf("%d",&p1->num);scanf("%f",&p1->num);试试。另外我在“[原创]你知道为什么吗?”也有该问题的讨论。
daizh 2003-10-17
  • 打赏
  • 举报
回复
I perform it successfully using VC++6.0
Wolf0403 2003-10-17
  • 打赏
  • 举报
回复
you must be using TC2, which should be throw into the garbage bin now.
oldhunter 2003-10-17
  • 打赏
  • 举报
回复
don't successful,it's still alert fllowing:

floating point formats not linked
Abnormal program termination.
daizh 2003-10-17
  • 打赏
  • 举报
回复
#include <malloc.h>
#include <stdio.h>//to be added
#define NULL 0
#define LEN sizeof(struct student)
struct student
{
int num;
float score;
struct student *next;
};

struct student *creat(void);
void print(struct student *);

void main()
{
struct student *p;
p = creat();
print(p);
}

struct student * creat(void)
{
struct student *head,*p1,*p2;
int n=0;
p1 = p2 = (struct student *) malloc(LEN);

scanf(" %d %f", &p1->num, &p1->score);//pay attention to this palce.

head = NULL;
while(p1->num != 0)
{
++n;
if (n==1)
head = p1;
else
p2->next = p1;
p2 = p1;

p1 = (struct student *)malloc(LEN);
scanf("%d,%f", &p1->num, &p1->score);
}

p2->next = NULL;

return head;
}

void print(struct student *p)
{
while(p != NULL)
{
printf("num: %d\tscore: %.2f\n", p->num, p->score);
p = (*p).next;
}
}
xiaosatan 2003-10-17
  • 打赏
  • 举报
回复
你的错误可能在scanf("%d,%f",&p1->num, &p1->num);上,把&p1->score改成&(p1->score)试试。
oldhunter 2003-10-17
  • 打赏
  • 举报
回复
what is the "stl"?
I am studing the Link,so must try it.
can you help me, expert?
ttlb 2003-10-17
  • 打赏
  • 举报
回复
为什么要这样?stl 里不时有现成的链表吗?

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧