
structures within structures
Quote:
> if i had two structures defined as follows.
> struct struct1
> {
> int a;
> int b;
> };
> and
> struct struct2
> {
> struct struct1;
> int a;
> int b;
> };
> if i created a structure as 'struct struct2 smine;' in a program.
> how would i then put a value into the int a of the struct1 part of smine,
> and, of course, get it out?
If you added in a 'next_struct(x)' statement to both structs, you would
be on your way to creating an orthogonal linked list! (View that as a
literal BTW).
If you wanted to access and place info into int a of struct2, try this:
struct2.struct1.a = 5;
Printing it out would be the same way:
printf("Int value is %4d\n", struct2.struct1.a);
ANother thing you can do to save whitespace and make your code a bit
more readable is to do this from within the function(s) you are
accessing the structs from:
struct struct2 fubar;
fubar = struct2.struct1;
Then when you access the int of struct1, you can use:
fubar.a = 5;
This is based on code that I am using for a current working program that
works quite well.
Joe Cipale
< The opinions expressed are my own and not those of Intel >