Skip to content

Instantly share code, notes, and snippets.

@nramsbottom
Created October 5, 2014 09:49
Show Gist options
  • Select an option

  • Save nramsbottom/43bb5f74f84ef69802a9 to your computer and use it in GitHub Desktop.

Select an option

Save nramsbottom/43bb5f74f84ef69802a9 to your computer and use it in GitHub Desktop.
static char *keyword;
static char *args[10]; // array of pointers to the arguments (stored in command)
int parse_command(char *command, char **keyword, char *args[]) {
char *tmp;
int n;
tmp = strtok(command, " ");
if (tmp != NULL)
*keyword = tmp;
n=0;
while (tmp != NULL) {
tmp = strtok(NULL, " ");
args[n++] = tmp;
}
return n; // return the number of arguments parsed
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment