/* Declare the function pointer. Variable 'state_machine' is a pointer to a function that takes no parameters and doesn't return anything. */
void (*state_machine)(void);
/* State functions */
void hello(void) {
write("Hello ");
state_machine = world; // State transition
}
void world(void) {
write("World!");
state_machine = newline; // State transition
}
void newline(void) {
write("\n");
state_machine = hello; // State transition
}
/* Main function */
void main(void){
state_machine = hello; // Initialize function pointer to the first state
while(1){
state_machine(); // This is all that is needed to keep FSM running
}
}