This is part of my project, I'm trying to get the size of the stack (which in this case should be 0) after initialization. After exiting the function, it returns an arbitrary value. Howcome?Code:struct _Link { int x; int y; struct _Link *next; }; typedef struct _Link Link; struct _LinkList { int size; Link *head; Link *tail; }; typedef struct _LinkList LinkList; struct _Stack { LinkList *l; }; typedef struct _Stack Stack; Stack* stack_init() { Stack *s; LinkList *l; s = (Stack*)malloc(sizeof(Stack)); s->l = (LinkList*)malloc(sizeof(LinkList)); s->l->size =0; s->l->head = NULL; s->l->tail = NULL; return s; } void stack_check() { Stack *s; s = stack_init(); if(s==0) printf("correct"); }
Note, the linked list has already been initialized.
Any help will be greatly appreciated.