Skip to content

Instantly share code, notes, and snippets.

@liuml07
Created July 4, 2013 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liuml07/5926431 to your computer and use it in GitHub Desktop.
Save liuml07/5926431 to your computer and use it in GitHub Desktop.
Build the argv list from command line
int parseline(char *buf, char **argv) {
char *delim;
int argc = 0;
buf[strlen(buf) - 1] = ' ';
while (*buf && (*buf == ' '))
buf++;
while ((delim = strchr(buf, ' '))) {
argv[argc++] = buf;
*delim = '\0';
buf = delim + 1;
while (*buf && (*buf == ' '))
buf++;
}
argv[argc] = NULL;
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment