help with nested structs and pointers

hello all

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;
};

and the offending line:

strcpy((*mPtr).(*reelsymbols[/u]).sname, (*slPtr).sname);

mPtr is a pointer to an array of real structs.
slPtr is a pointer to an array of symbol structs.

So i need to figure out how to get the information from the symbol struct array into the nested array within the second struct without using offsets.

Any suggestions?
how does the definition of 'mPtr' and 'slPtr' look like?
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

strcpy( ( slPtr + j )->reelsymbols[k].sname, ( mPtr + i )->sname );
Last edited on
Topic archived. No new replies allowed.