Perfetto...è questo che non capisco. Il codice come ti dicevo non l'ho scritto io. Per completezza il metodo è questo:
codice:
int count_args(char *start_command, int *pipe_present, char **next_command) {
char copied_string[COMMAND_LENGTH + 1];
char *temp, *temp_next;
int args = 0, i;
strcpy(copied_string, start_command);
if (((temp = strtok(copied_string, " \n")) == NULL) || (strcmp(temp, "\0") == 0)) return(-1);
args++;
while (((temp = strtok(NULL, " \n")) != NULL) && (strcmp(temp, "|") != 0 )) {
if (strcmp(temp, "\0") == 0 ) break;
args++;
}
if (temp == NULL) {
*pipe_present = 0;
*next_command = NULL;
} else {
if ((temp = strtok(NULL, " \n")) != NULL) {
*pipe_present = 1;
for (i=0; ; i++) if (copied_string[i] == '|') break;
*next_command = start_command + i + 2;
}
else {
*pipe_present = 0;
*next_command = NULL;
}
}
return(args);
}