So i have a simple C file with the intention of making a pile but i keep having trouble with a function that checks if the pile is empty:
int checkEmpty(pile a)
{
return a->top==NULL;
}
say that i declared a function that constructs me an empty pile with a->top=NULL
edit: giving more info
i defined pile by:
typedef struct{
info* top;
}pile_t;
typedef pile_t* pile;
info is another structure, my program compiles but it stop working when the it uses the function
edit: my bad, this is the code i am using:
typedef struct elem_t{
int num;
struct elem_t* next;
}elem_s;
typedef elem_s* elem;
typedef struct{
elem top;
}pile_s;
typedef pile_s* pile;
elem consElem(int i){
elem p=(elem)malloc(sizeof(elem_s));
p->num=i;
p->next=NULL;
return p;
}
pile consPile(){
pile a=(pile)malloc(sizeof(pile_s));
a->top=NULL;
return a;
}
bool checkEmpty(pile A){
return A->top==NULL;
}
void main(){
pile A=consPile();
printf("%d",checkEmpty(A)==TRUE);
}