请大家帮我检查一下,我下面的程序出现在什么地方

laodiao 2003-10-29 11:27:11
#include <stdio.h>
#include <alloc.h>

main()
{
struct mystruct{
float num01;
float num02;
};

struct mystruct *p,str;
p=(struct mystruct *)malloc(1000);
printf("\nGood1");
scanf("%f,%f",&p->num01,&p->num02);
p=&str;

printf("%f,%f",p->num01,p->num02);
}
...全文
99 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
021850524 2003-10-30
  • 打赏
  • 举报
回复
虽然能通过,但有强制转换,正如楼上所说.
不过你要是用的是tc2.0的话,可能会报错.
  • 打赏
  • 举报
回复
问csdnxw(大家帮忙):
就把程序改成这样(如下),也不行,出错提示是:
--------------------------------------------------
scanf: floating point format not linked
然后是程序非正常结束。
还有,在跟踪的过程中,内存可以分配,但就是对浮点型数据出错,把这里的浮点型
换成整型就没有问题了。
--------------------------------------------------

#include <stdio.h>
#include <alloc.h>

main()
{
struct mystruct{
float num01;
float num02;
};

struct mystruct *p,str;
p=(struct mystruct *)malloc(sizeof(str));
scanf("%f,%f",&p->num01,&p->num02);
printf("%f,%f",p->num01,p->num02);
}
panzhaoping 2003-10-30
  • 打赏
  • 举报
回复
up
laodiao 2003-10-30
  • 打赏
  • 举报
回复
怎么样才能得到一个正确的运行程序那?
如果将浮点型改为整形,此程序可以工作正常。。
csdnxw 2003-10-29
  • 打赏
  • 举报
回复
搂主,你随便找了一块内存来强制作为你的结构类型啊?
不知道操作系统愿不愿意
不过在Dos/98下应该可以
最起码Dos应该可以
2000下绝对不可以
除非,找到了漏洞
playboyxp 2003-10-29
  • 打赏
  • 举报
回复
你应该先让p指向str而不是开了内存后再让他指向str
指向后就不用开内存了
#include <stdio.h>
#include <alloc.h>
main()
{
struct mystruct{
float num01;
float num02;
};

struct mystruct *p,str;
printf("\nGood1");
p=&str
scanf("%f,%f",&p->num01,&p->num02);
printf("%f,%f",p->num01,p->num02);
}

69,382

社区成员

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

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