Mail Archives: djgpp/1997/05/20/14:35:15
David Orme (phreadd AT powerup DOT com DOT au) writes:
> This is slightly off topic but please help.
>
>
> I want to do something like this:
> a->b[i].d[j] = &(a->c[k]); /* the &() is wrong, I get a sigsev fault */
>
> where "d" is an array of pointers
> and "c" is an aray of integers
>
> How do I make d[j] point to the address of b[k]?
>
> Please don't recommend I abolish "a", although that does make the assignment
> operation simpler (I've done it before, it's b[i].d[j] = &c[k]).
>
> The nested properties of this structure are required for my program as it
> makes the rest of the program simpler, though longer :-)
I suspect that i, j, or k are out of th array bounds. Note that if c[] was
declared as an int c[6] then valid k's are 0, 1, 2, 3, 4, and 5, but 6
will cause a segfault.
Also, if you have an array c by itself, sized say 10, and an array c
member of struct a, sized 6, then there are two different arrays and c[10]
is valid but a->c[10] is not.
Also, a must be a pointer to a struct, and if member c is a pointer and
not directly declared as a fixed size array, then you have to malloc the
space for your array and assign the returned pointer to a->c, checking for
NULL, BEFORE any reference to a->c[k].
--
.*. Where feelings are concerned, answers are rarely simple [GeneDeWeese]
-() < When I go to the theater, I always go straight to the "bag and mix"
`*' bulk candy section...because variety is the spice of life... [me]
Paul Derbyshire ao950 AT freenet DOT carleton DOT ca, http://chat.carleton.ca/~pderbysh
- Raw text -