Solving the problem is what counts. Being "elegant" or something can be a second goal most of the time.
What is the purpose of these lines:
Code:
com[strlen(com) + 1] = '\0';
val[strlen(val) + 1] = '\0';
If you can run strlen on the arguments, then there already is a '\0' there. Do you need to ensure there are two '\0's at the end of the string?
Why not pass in the com and val buffers as arguments to the function? Then you can call it easily from an outer function:
Code:
read_special_command(cmd);
parse_command(cmd, arg1, arg2);
Also its up to you but I like to name it the other way, command_read, command_parse, etc. Then all the "command_" stuff sorts nicely together
EDIT: You can replace
Code:
chr = str;
while (*str)
{
...
chr++;
}
with
Code:
for (chr = str; *str; chr++)
That's what a for loop is for