This is in my main.c
int main(){
int size = 5;
Path Solution;
PathInit(&Solution,size);
printf("Size: %d\n",Solution.size);
printf("top: %d", Solution.top);
}
This is in my path.h
typedef struct{
int size;
int top;
int *item;
}Path;
This is in my path.c
void PathInit(Path *P, int vsize){
P = (Path *)malloc(sizeof(Path));
P->size = vsize;
P->item = (int *)malloc(sizeof(int)*vsize);
P->top = -1;
}
The expected output is
Size: 5
top: -1
However the output is something along the lines of
Size: 3412832
top: 0
Can someone explain why my struct is not initializing properly. Also this isn't my full code but ive narrowed the problem down to these sections. Any help would be great. Thanks