Originally posted by: cchen
I'm a little bit confused....
you say: struct players * playerlist; // then readFile(playerlist) is correct
that is what i did, but i don't think it passed by reference... after the function returns, the memory should be allocated for playerlist, but i'm debugging right now and the memory is still unallocated afterwards... which leads me to believe that this is still passing by value
If I understand this right, the procedure readFile should be prototyped:
readFile(players **player_list);
IMO, AgentEL answered your original question correctly, but you asked the wrong question. If readFile is dynamically allocating memory, the call should look like:
*playerlist = (struct players *) malloc(LIST_SIZE * sizeof(struct players));
The reason is that the scopes are independent within the original caller and the callee (inside readFile). If you pass in a pointer and reassign the return value of malloc to that pointer, the allocated memory does not propogate back up to the caller. That leaves you with a memory leak, and the pointer in the caller is still undefined once you exit readFile.
Sigh, I didn't explain it as well as I'd have liked.
Is readFile a good procedure name for what it's worth?