ohmygod thts abs great! u r a genius!
but i have a Q. can i not pass a copy of aCar instead of the address? will it not then be solved?
Printable View
ohmygod thts abs great! u r a genius!
but i have a Q. can i not pass a copy of aCar instead of the address? will it not then be solved?
Passing structs around is not good practice, as they tend to be rather big (or can get to be so), and cause problems, so stick with passing addresses.
>>cInv->pList[cInv->curSize] = (Car *)malloc(sizeof(Car));
Here you malloc()'d memory to hold the structure. All you need do now is put the structure in it.
>>cInv->pList[cInv->curSize] = aCar;
Here you've goofed, because you're overwritten your pointer to your malloc()'d memory with another pointer. Now you can't free the memory you malloc()'d.
So, to fix it:
Change:
>>cInv->pList[cInv->curSize] = aCar;
To :
>>*(cInv->pList[cInv->curSize]) = *aCar;
I think the syntax is correct, it's late and I could be wrong!
Basically you can copy structs by direct assignment.
it works!!! thank u so much. i was trying to figure this out for the last 6 hrs. shows how dumb i am. :-) thanx again!