Change your code to this. You try to use something you haven't yet defined.
Code:
struct memstate
{
char output0; //output if next input is 0
char output1; //output if next input is 1
struct memstate *prev; //prev if input is 0, next if 1
struct memstate *next;
};
//------------------------------------------------------------------------------
//Creates state machine and passes back pointer to 00 state
void state_init(struct memstate* startpoint)
{
//Initialise states
struct memstate states[4];
...
I also removed the extern, but if you believe that you need it for some reason, say it.
Also, in the function, what is state? You wanted to say states?
Also the comment // Initialise states should be // Initialize states (but of course this does not cause any error or warning.
You had
Code:
startpoint = states[0];
but startpoint is a pointer to the struct and states[0] is a struct, so you might want to use it that way
Code:
startpoint = &states[0];
You have this
Code:
static struct memstate current_state;
if(start == 1)
{
state_init(*current_state);
But the function requires a pointer, so you have to call the function like this
Code:
state_init(¤t_state);
Then you have this
Code:
output = current_state.output1;
current_state = current_state->next;
and you are confused because next is a pointer. However, the current_state is the key to decide if you are going to use the arrow operator -> or the dot operator . .Since current_state is not a pointer, you need to write this
Code:
output = current_state.output1;
current_state = current_state.next;
Likewise for the prev.
Ok then, you have, inside the function again, this ( assuming you meant states instead of state)
Code:
states[0].next = states[1];
as another similar thing I said before, you have a pointer to the struct and the struct, so you need to assign the address of the struct, like this
Code:
states[0].next = &states[1];
Same thing stands for some other equivalent lines of code in the function.
Now back in main, we have done this change
Code:
current_state = current_state.next;
But what you want is to go the next struct. For this I would suggest you to use a pointer. If you read my post, then you might be able to figure out what changes you need to make.
Also about b01 inside the function, are you trying to use octal numbers?