Complete the code to define the initial state of the state machine.
typedef enum { STATE_IDLE, STATE_PROCESSING, STATE_ERROR } State;
State currentState = [1];The initial state is usually set to STATE_IDLE to indicate the machine is waiting to start.
Complete the code to declare a nested (sub) state inside the PROCESSING state.
typedef enum { SUBSTATE_READ, SUBSTATE_WRITE } ProcessingSubState;
ProcessingSubState currentSubState = [1];The substate SUBSTATE_READ is often the first step in processing data.
Fix the error in the transition function to correctly change the state.
void transitionToProcessing(State *state) {
*state = [1];
}The function should set the state to STATE_PROCESSING to indicate the machine is now processing.
Fill both blanks to complete the hierarchical state check.
if (currentState == [1]) { if (currentSubState == [2]) { // Handle read substate } }
Check if the main state is STATE_PROCESSING and the substate is SUBSTATE_READ to handle reading.
Fill all three blanks to complete the hierarchical state machine transition.
switch (currentState) {
case [1]:
switch (currentSubState) {
case [2]:
currentSubState = [3];
break;
}
break;
}This code switches from SUBSTATE_READ to SUBSTATE_WRITE inside the STATE_PROCESSING main state.