Well, I think I´ve found a better way of doing what I need. I´ve done this:
Code:
#include <stdio.h>
#include <string.h>
main() {
//char line[]="Hello World !!";
//char line[]="Hello My Big World !! 1 2 3 4 5 6 7 8 9 0";
char line[]="Hello My Big World";
//char line[]="15 /usr/bin/php /html/echo.php 8";
//char line[BUFSIZ];
//strcpy(line,"Hello My Big World");
func(line);
}
func(char *ptr) {
int y=0,c=0,n,len=0,x=0;
char periodicidade[BUFSIZ];
char path[BUFSIZ];
char field[BUFSIZ];
char *p_texto = ptr;
while ( sscanf(ptr, "%50[^ ]%*c%n", field, &n) == 1 )
{
len = strlen(ptr);
ptr += n;
switch(c) {
case 0:
strcpy(periodicidade,field);
printf("field[%d]: [%s]\n",c,field);
break;
/*
case 1:
printf("field[%d]: [%s]\n",c,field);
break;
case 2:
printf("field[%d]: [%s]\n",c,field);
break;
*/
default:
strcat(path,field);
strcat(path," ");
printf("default->field[%d]: [%s]\n",c,field);
break;
} //switch
c++;
} //while
puts("");
puts("=====================================================");
printf("periodicidade: [%s]\n",periodicidade);
printf("path: [%s]\n",path);
}
The result was:
field[0]: [Hello]
default->field[1]: [My]
default->field[2]: [Big]
default->field[3]: [World]
default->field[4]: [d]
default->field[5]: [@]
================================================== ===
periodicidade: [Hello]
path: [My Big World d @ ]
As we can see at the end of the string there are some trashed chars... I think that is info on memory...
Can anyone explain what is this and how to take it off ?
Thanks again,