Here is a strtok() version of splitting the command:
char** split(char *command, int* size) {
char** ret;
char* t;
int i;
for(i=0, t=strtok(command, " "); t!=NULL;++i ) {
ret[i]=t;
t = strtok(NULL, " ");
}
*size = i;
return ret;
}
You can use it like this:
char** args;
int nArgs;
args = split(buffer, &nArgs);
// you can now eg. execvp("/bin/ls", args)