Accessing elements of a pointer pointer WITHIN a function after passing it as an argument causes my program to crash.
For example
INITIALIZATION:
edge **graph;
graph = malloc(e*sizeof(edge));
for(int i = 0; i< e;i++){
graph[i] = malloc(sizeof(edge));
}
After initialization, this works:
printf("%d\n", graph[i]->cost);
But after passing it on to a function it crashes:
Function(edge **graph){
//stuff
printf("%d\n", graph[i]->cost); //this causes a crash
}
What's causing this? Thanks in advance! :D
graph = malloc(e*sizeof(edge));should begraph = malloc(e*sizeof(*graph));ormalloc(e*sizeof(edge*))