A note about command processing.
You may use if..else
statements of course. I suggest more elegant solution using arrays.
If you understand the solution with arrays, then processing commands can be implemented in the similar way.
Suppose you have 3 commands. Each command will have its unique id starting form 0 (zero) to 2.
You can store a function that will execute the command in the array;
// This function will execute command 0
// This function will execute command 2
// Note that all above functions have the same prototype: they receive void and return void
// We now need to define a type of this functions
typedef void (*command_executor_type)();
// Now we define array of those functions
command_executor_type exec_commands =
Now, in order to run the command, according it's id
1. first access the corresponding array entry using '[ ]'. for command with id 0 (zero) it would be
2. The entry, stored in the entry of array is function (actually the address of function, but that does not matter). We call functions using '()':
char curr_command = 0; // get command id here 0-2
// execute the command