0
#include <iostream>
typedef struct _elems {
    int a;
    int b;
    int c;
}elems;
static elems eArray1[]={{5,9,13}, {12,22,1}, {2,3,4},{4,3,1}};
static elems eArray2[]={{23,121,55}, {88,23,90}};

eArray1 and eArray2 can have different sizes such as 1x3, 2x3, 4x3, 5x3, etc.How to combine these ,eArray1 and eArray2, into a structure called eArray and loop and print all its sub elements in this way:
std::cout << a << b << c << std::endl;?

Edited by pritaeas: Moved.

2
Contributors
1
Reply
22
Views
3 Years
Discussion Span
Last Post by Ancient Dragon
0

One way to do it is like below. I'd also put the number of elements in each array into the combined structure so that you know how big the arrays are at runtime.

typedef struct _elems {
    int a;
    int b;
    int c;
}elems;

typedef struct _elms {
    elems *e1;
    elems *e2;
    int e1Size;
    int e2Size;
} earray;

static elems eArray1[]={{5,9,13}, {12,22,1}, {2,3,4},{4,3,1}};
static elems eArray2[]={{23,121,55}, {88,23,90}};

static earray e = {eArray1, eArray2, sizeof(eArray1)/sizeof(eArray1[0]), sizeof(eArray2)/sizeof(eArray2[0])};

int main()
{
}

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.