首页 > 其他 > 详细

Adding a struct into an array(stackoverflow)

时间:2015-03-31 09:01:02      阅读:205      评论:0      收藏:0      [点我收藏+]

Question:

So lets say I have a struct like this:

struct example_structure 
{
int thing_one;
int thing_two;
};

I also have an empty array which I am trying to fill with these structs. I am trying to add them as follows, but it doesn‘t seem to be working:

array[i].thing_one = x;
array[i].thing_two = y;

Instead of this is there a way to declare a variable of type example_structure and then add that to the array?


Answer:

struct example_structure 
{
    int thing_one;
    int thing_two;
} myarray[100];

And then you would access those array elements like any other array:

myarray[10].thing_one=123;
myarray[10].thing_two=456;

if that is what you are trying to achieve.


website:

http://stackoverflow.com/questions/29353253/adding-a-struct-into-an-array

Adding a struct into an array(stackoverflow)

原文:http://blog.csdn.net/u013152895/article/details/44769399

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!