Serial Input Basics

The way I usually handle this is once a complete line is received, immediately use strtok() to step through the line finding each token. Each time strtok() returns a token pointer, stick it an an array of pointers, keeping track of the number of tokens. When done, you have an array of tokens (each token is NULL terminated) and a count, just like argc/argv[] passed to a C main function. It is this array that is repeatedly accessed while determining the current command and it's semantics, it is no longer necessary to parse the original string.

This has a few advantages, like knowing the number of tokens right from the start (makes it easier to validate a complete correct command sequence as soon as you decode the command ID in the first token), plus it eliminates the need to parse the string more than once, and does not require an extra copy of the string or special storage of each token.

Of course, the downside is that it changes the original string, and is a bit more complicated of a concept which starts to move it away from a "basics" discussion.