Can someone tell me, why I can't allocate memory to the struct array through the init() function? When done manually in main, everything is fine. When trying it through init() nothing happens (Also no error message). The adress is always 0x0, I guess the null pointer.
#define GAMES 100
typedef struct{
double *scores;
}SCORES;
void init(SCORES *arr);
int main(){
SCORES *numbers = NULL;
init(numbers);
printf("Adress is: %p\n", numbers); //Still 0x0
return 0;
}
void init(SCORES *arr){
arr = (SCORES*) malloc(GAMES * sizeof(SCORES));
}
Trying it with the code below works for malloc. I get an adress but if I use free(), memory is still allocated.
void init(SCORES **arr){
*arr = (SCORES*) malloc(GAMES * sizeof(SCORES));
}
...
init(&numbers);
...
free(numbers);