Just a state machine pattern using C programming language