I\'ve been trying to wrap my head around this the whole day...
Basically, I have a struct called State that has a name and another one called StateMachine with a name, a
You're doing a conceptual error:
State ** states;
It's true that you can consider states like an array of pointer to State object, but you are allocating space for just one state. When you do:
state_machine->states[state_machine->total_states]= temp;
you are doing something wrong if total_states is greater than zero because you are pointing to memory segments that are not been allocated (I'm wondering why you don't get a SEGFAULT). To store a dynamic number of State this way you need a linked list, or to call realloc every state you add(but that's not a good idea). The memory you are allocating with different malloc calls isn't continuous.