结构数组的问题 [英] Problem with array of structures

查看:80
本文介绍了结构数组的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我这段代码有什么问题吗?编译器错误

是:在''之前解析错误。'''token"在第13-16行。我尝试搜索

互联网,但所有参考指南等都说它没关系。这是一个问题

与编译器?我正在使用dev-c ++前端进行mingw。


/ *开始代码* /

#include< stdio.h>


typedef struct

{

int x;

int y;

int width;

int height;

}障碍BB;


障碍障碍物障碍物[1];

障碍物[0] .x = 0;

障碍物[0] .y = 0;

障碍物[0] .width =(OFFSET_X * 2 );

障碍[0] .height =(OFFSET_Y * 2);


int main(无效)

{

返回0;

}

/ *结束代码* /

解决方案

Ian Tuomi< ia*@co.jyu.fi>这样说:

障碍BB障碍[1];
障碍物[0] .x = 0;
障碍物[0] .y = 0;
障碍物[0] .width =(OFFSET_X * 2);
障碍物[0 ] .height =(OFFSET_Y * 2);




障碍物是一个指向结构的指针(这就是你声明一个
$时得到的结果) b $ b数组),所以要访问元素,你想做障碍[0] - > x等等。


-

Christopher Benson -Manica | Jumonji giri,荣誉。

ataru(at)cyberspace.org |


Christopher Benson-Manica写道:

Ian Tuomi< ia*@co.jyu.fi>这样说:

障碍物障碍物[1];



障碍物[0]。 x = 0;
障碍物[0] .y = 0;
障碍物[0] .width =(OFFSET_X * 2);
障碍物[0]。高度=(OFFSET_Y * 2) ;



障碍是指向结构的指针(这是你声明一个
数组时得到的),所以要访问元素,你想要做障碍[ 0] - > x等




哦当然!非常感谢你!


Ian Tuomi写道:

Christopher Benson-Manica写道:
< blockquote class =post_quotes> Ian Tuomi< ia*@co.jyu.fi>这样说:

障碍物障碍物[1];


障碍物[0] .x = 0;
障碍物[0] .y = 0;
障碍物[0] .width =(OFFSET_X * 2);
障碍物[0] .height =(OFFSET_Y * 2);


障碍是一个指向结构的指针(这是你在声明一个
数组时得到的),所以要访问元素,你想做障碍[ 0] - > x等



哦当然!非常感谢!




嗯..对不起我得出了结论,但现在它说:

之前解析错误 - > ;''标记'所以看起来我或者仍然有一个问题或者错误的介绍你的消息非常糟糕。


Could anyone please tell me what is wrong with this code? Compiler error
is: "parse error before ''.'' token" in lines 13-16. I tried searching the
internet but all the reference guides etc. say It''s ok. Is it a problem
with the compiler? I am using the dev-c++ front-end for mingw.

/* start code */
#include <stdio.h>

typedef struct
{
int x;
int y;
int width;
int height;
}ObstacleBB;

ObstacleBB obstacles[1];

obstacles[0].x = 0;
obstacles[0].y = 0;
obstacles[0].width = (OFFSET_X * 2);
obstacles[0].height = (OFFSET_Y * 2);

int main(void)
{
return 0;
}
/* end code */

解决方案

Ian Tuomi <ia*@co.jyu.fi> spoke thus:

ObstacleBB obstacles[1]; obstacles[0].x = 0;
obstacles[0].y = 0;
obstacles[0].width = (OFFSET_X * 2);
obstacles[0].height = (OFFSET_Y * 2);



obstacles is a pointer to a struct (that''s what you get when you declare an
array), so to access elements, you want to do obstacles[0]->x, etc.

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cyberspace.org |


Christopher Benson-Manica wrote:

Ian Tuomi <ia*@co.jyu.fi> spoke thus:

ObstacleBB obstacles[1];



obstacles[0].x = 0;
obstacles[0].y = 0;
obstacles[0].width = (OFFSET_X * 2);
obstacles[0].height = (OFFSET_Y * 2);


obstacles is a pointer to a struct (that''s what you get when you declare an
array), so to access elements, you want to do obstacles[0]->x, etc.



Oh ofcourse! Thankyou so much!


Ian Tuomi wrote:

Christopher Benson-Manica wrote:

Ian Tuomi <ia*@co.jyu.fi> spoke thus:

ObstacleBB obstacles[1];


obstacles[0].x = 0;
obstacles[0].y = 0;
obstacles[0].width = (OFFSET_X * 2);
obstacles[0].height = (OFFSET_Y * 2);



obstacles is a pointer to a struct (that''s what you get when you
declare an
array), so to access elements, you want to do obstacles[0]->x, etc.



Oh ofcourse! Thankyou so much!



Umh.. sorry I jumped into conclusions but now it says:
"parse error before ''->'' token" so looks like I either still have a
problem or mis-interperted youre message really badly.


这篇关于结构数组的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆