Adding a struct into an array(stackoverflow)

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

时间: 2024-11-07 18:12:29

Adding a struct into an array(stackoverflow)的相关文章

Why is processing a sorted array faster than an unsorted array(Stackoverflow)

What is Branch Prediction?Consider a railroad junction:Image by Mecanismo, via Wikimedia Commons. Used under the CC-By-SA 3.0 license.Now for the sake of argument, suppose this is back in the 1800s - before long distance or radio communication.You ar

【Stackoverflow好问题】将数组转换为List

问题 假设有数组 Element[] array = {new Element(1),new Element(2),new Element(3)}; 如何将其转换为ArrayList<Element> arraylist呢? 精华回答 Arrays.asList(array)或者Arrays.asList(new Element(1),new Element(2),new Element(3)) 不过,这样做有些坑要注意: 1.这样做生成的list,是定长的.也就是说,如果你对它做add或者r

(java oracle)以bean和array为参数的存储过程及dao部分代码

一.数据库部分 1.创建bean对象 1 CREATE OR REPLACE TYPE "QUARTZJOBBEAN" as object 2 ( 3 -- Author : Duwc 4 -- Purpose : for QuartzJobBean 5 job_name varchar2(200), 6 job_group varchar2(200), 7 job_class_name varchar2(250), 8 trigger_name varchar2(200), 9 tr

hive中导入json格式的数据(hive分区表)

hive中建立外部分区表,外部数据格式是json的如何导入呢? json格式的数据表不必含有分区字段,只需要在hdfs目录结构中体现出分区就可以了 This is all according to this guide: http://blog.cloudera.com/blog/2012/12/how-to-use-a-serde-in-apache-hive/ 1 hive> ADD JAR /home/hadoop/hive-serdes-1.0-SNAPSHOT.jar; 2 Added

Android调用JNI本地方法经过有点改变

方法注册好后要经过哪些路 Android一个异常捕获项目 https://github.com/xroche/coffeecatch coffeecatch CoffeeCatch, a tiny native POSIX signal catcher (especially useful for JNI code on Android/Dalvik, but it can be used in non-Java projects) It allows to "gracefully"

VJass

JassHelper 0.A.0.0 Although World Editor&apos;s Jass compiler was finally replaced by PJass using WEHelper , there were a couple of other annoyances that still needed fixing, that&apos;s the reason this project begand. Later I felt like going furt

HIVE 原理

Overview HiveQL DDL statements are documented here, including: CREATE DATABASE/SCHEMA, TABLE, VIEW, FUNCTION, INDEX DROP DATABASE/SCHEMA, TABLE, VIEW, INDEX TRUNCATE TABLE ALTER DATABASE/SCHEMA, TABLE, VIEW MSCK REPAIR TABLE (or ALTER TABLE RECOVER P

Matlab中所有自定义的函数

Functions By Category | Alphabetical List Language Fundamentals Entering Commands ans Most recent answer clc Clear Command Window diary Save Command Window text to file format Set display format for output home Send cursor home iskeyword Determine wh

Hive之内置函数

函数分类 UDF(User Defined Function):数据一对一 UDAF(User Defined Aggreation Function):数据多对一 UDTF(User Defined Table-Generating Function):数据一对多 group by / sort by 对函数处理过的别名报错处理,假如:select f(col) as fc, count(*) as cnt from table_name group by fc; 解决方法1,套一层子查询:s