I'm trying to copy a data member from one stuct into a seecond struct that has an array of the first struct types nested inside it, but I am having trouble accessing the data members and get the following error:
‘reelsymbols’ was not declared in this scope
error: expected unqualified-id before ‘(’ token
I think I need a pointer to the array of nested structs, but the compiler won't let me create a pointer within the struct?
here is my structs:
struct symbol {
char sname[7];
bool bonus;
int value;
};
struct real {
symbol reelsymbols[numreelsymbols];
int payline;
};
if I have correctly understood you are trying to copy member sname of an object of struct symbol to an element of array reelsymbols of an object of struct real.
Let assume that i - is an index of the element of reelsymbols that must be assigned. Then the code snip will look
1 2 3 4
symbol src;
real dest;
strcpy( dest.reelsymbols[i].sname, src.sname );
where 0 <= i < numreelsymbols
Or if you are using arrays and pointers the code snip will look
symbol src[10];
real dest[20];
symbol *mPtr = src;
real *slPtr = dest;
int i = 5; // element of src
int j = 10; // element of dest
int k = 3; // element of reelsymbols