Hello All,
I'm trying to split a line like this:
15 /usr/bin/php /html/echo.php 8
I split paramaters using space char as the delimiter. I need to put the first par (15) and a variable and all the rest to another variable. I've tryed to do this using strtok, I can read all the params but didnt had success to put all the other pars to one unique variable.
Here is a small part of my code:
Can anybody point me a better way to do this ?Code:while(c<1000) {
if(c==0) {
strcpy(comando,token);
} else { //if(c==1) {
strcpy(valor,token);
x = strlen(valor)-1;
if(valor[x] == CHAR_RETURN) {
puts("fim!");
break;
}
}
printf("valor: [%s]\n",valor);
printf("Xtoken: [%s]\n",token);
token = strtok( NULL, CHAR_DELIM );
printf("token2: [%s]\n",token);
printf("before->buffer: [%s]\n",token);
sprintf(buffer,"%s %s",buffer,token);
printf("after->buffer: [%s]\n",token);
printf("===========> c: [%d]\n",c);
c++;
}
Thanks in advance,