Three implementations:
demo_switch.c
most basic, switch-based state machinedemo_functions.c
a little nicer on the eye with functions as state handlersdemo_functions_results.c
a more generic state machine framework with reconfigurable state transitions
$ gcc demo_switch.c && ./a.out
(0)> s
(1)> w
(1)> w
(1)> w
nice work
we're done
$ gcc demo_switch.c && ./a.out
(0)> 1
(0)> 2
(0)> 3
(0)> s
(1)> w
(1)> w
(1)> X
whoops (X)
we're done