(GAH. Why? Why did it all have to disappear??? sorry for my frustration. After typing out my problem for about half an hour I was required to log back in, losing all of my work.)
Hello all again,
Because I don't want to type everything I said again, I'll just shorten it.
I have an array of a struct (named CAR). this array is named "cars" (its inside a struct named park)
I could do this to set a variable in one of the cars:Code:typedef struct park { CAR cars[NUM_CARS]; } Park;
But I needed a second array named dock. This array should have a link to certain CARs in the "cars" array. I tried this code.Code:p->cars[i].variable=something; // This would work
unfortunately, changing something in "cars" didn't change the same CAR in "dock." When I set one equal to the other, it copied instead of making a link.Code:p->cars[i].variable=something; p->dock[j]=p->cars[i]; p->cars[i].variable=something_different; // I want this to also affect p->dock[j]
I realized my mistake and needed to have an array of pointers instead of an array of CARs. My new code:
now I can copy cars correctly (by copying their address), but I can no longer set variables:Code:typedef struct park { CAR* cars[NUM_CARS]; CAR* dock[NUM_CARS]; } Park;
So what did I do wrong and how do I fix it?Code:p->dock[i]=p->cars[i]; // this now works. p->dock[i].variable = something; // this gives me a syntax error p->dock[i]->variable = something; // this crashes the program upon executing
Thanks for listening,
Kairos
P.S. I kinda wrote this in a hurry and not as well since everything died. If this doesn't make sense please tell me and I will clear it up for you.



LinkBack URL
About LinkBacks



.