This is a classic mistake that beginners do.
Let's take a look at your main function:
int main()
{
Pilha* Stack; // This line is your problem!
create_empty_stack(Stack);
}
If you remember pointers, the declaration Pilha* Stack;
makes Stack be a memory pointer. But right now it doesn't point to anything, because you did not reserve memory for an object of type Pilha!
Your program crashes because create_empty_stack() tries to access next, a member of this object (remember that this object still doesn't exist).
So, what you should be doing instead is:
int main()
{
// Reserve space in memory for one Pilha object and
// make Stack point to this memory address.
Pilha* Stack = (Pilha*) malloc(sizeof(Pilha));
create_empty_stack(Stack);
}
Or a much simpler approach:
int main()
{
Pilha Stack; // Declare a new Pilha object
// and pass the memory address of this new object to create_empty_stack()
create_empty_stack(&Stack);
}