下面的代码那里错了

syoyc 2003-08-19 11:39:53
struct node
{
RECT rect;
struct node* next;
}start,*node;

start.next=NULL;
node=&start;

node->next=(struct node*)malloc(sizeof(struct node)); //运行到这里错了
node=node->next;
node->rect.left=rect.left;
node->rect.right=rect.right;
node->rect.top=rect.top;
node->rect.bottom=rect.bottom;
node->next=NULL;
...全文
31 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
jack_wq 2003-08-19
  • 打赏
  • 举报
回复
没问题吧!
Jinhao 2003-08-19
  • 打赏
  • 举报
回复
看上去没有问题,如果是那点错了的话,就是内存分配失败。
jerryy 2003-08-19
  • 打赏
  • 举报
回复
我执行也没有问题,你是不是那写错了。
sevecol 2003-08-19
  • 打赏
  • 举报
回复
我执行没有问题呀。
nriet8357 2003-08-19
  • 打赏
  • 举报
回复
还是用new和delete吧,毕竟这样安全多了。
dofty 2003-08-19
  • 打赏
  • 举报
回复
你用的是什么环境?

错误信息是什么?



syoyc 2003-08-19
  • 打赏
  • 举报
回复
头文件里写:
struct node
{
RECT rect;
UINT nIDResource;
struct node *next;
}start,*mynode;

构造函数里写:
start.next=NULL;
mynode=&start;

普通地方写:
struct node* next1=new (struct node);
mynode->next=next1;//该句出错

mynode=mynode->next;
mynode->rect.left=rect.left;
mynode->rect.right=rect.right;
mynode->rect.top=rect.top;
mynode->rect.bottom=rect.bottom;
mynode->next=NULL;
为什么
Bandry 2003-08-19
  • 打赏
  • 举报
回复
错误信息了?
是不是没有包含头文件啊
Jinhao 2003-08-19
  • 打赏
  • 举报
回复
用dofty(dofty)的方法。
或者用new
syoyc 2003-08-19
  • 打赏
  • 举报
回复
我在头文件里写
struct node
{
RECT rect;
struct node* next;
}start,*node;

在构造函数里写
start.next=NULL;
node=&start;


在普通地方写
node->next=(struct node*)malloc(sizeof(struct node)); //运行到这里错了
node=node->next;
node->rect.left=rect.left;
node->rect.right=rect.right;
node->rect.top=rect.top;
node->rect.bottom=rect.bottom;
node->next=NULL;
njtu 2003-08-19
  • 打赏
  • 举报
回复
说说你的环境,并贴出较完整的代码。帮你看看
紫郢剑侠 2003-08-19
  • 打赏
  • 举报
回复
也许大家测试的环境不同罢.
dofty 2003-08-19
  • 打赏
  • 举报
回复
把node->next=(struct node*)malloc(sizeof(struct node));改成
if ( (node->next=(struct node*)malloc(sizeof(struct node)))==NULL )
{
printf("memory allocation failure, quiting...\n");
return (0);
}
GhostAdz 2003-08-19
  • 打赏
  • 举报
回复
rect是什么
syoyc 2003-08-19
  • 打赏
  • 举报
回复
start.next=NULL;
node=&start;
写在构造函数里行吗

69,369

社区成员

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

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