Greetings @Salem!
I managed to solve my problem without strtok (but I had the help of my uncle, and he is a very experienced programmer ), but I'm going to adapt my code with it because it will make so much easier when finding an 'item;' (since I will have three values in this line) if I use strtok, just need to put a int count inside the loop and store the third to fifth value, and now I understand and know how to use it!
Here is my solution without the strtok:
Code:
char *result2;
char *result3;
void *LocalizaItem(char *str) //str = "{015;scanner;7891150019508;;;29}";
{
char * pini;
char * pout;
char * pt1;
int pt2;
int pt3;
char buffer[1000], buffer2[1000], buffer3[1000];
char *result;
char nada[2] = "\0";
GtkTextIter diter;
/*======= Limpando globais no inicio da funcao =======*/
result2 = (char *)malloc(strlen(nada));
strcpy(result2,nada) ;
//printf("result monitorado==>%s<==\n", result2);
result3 = (char *)malloc(strlen(nada));
strcpy(result3,nada) ;
//printf("result monitorado==>%s<==\n", result3);
/*====================================================*/
pt1 = str;
if(strstr(str,"scanner;") != NULL){
printf("\n=======================================\n");
printf("===== 'scanner' found in log =====\n");
printf("=======================================\n");
if((pini = strstr (str,"scanner;"))== NULL)
{
strcpy(buffer," ");
}
pini = pini + (strlen("scanner;"));
pt2 = pini - pt1 ;
if((pout = strstr (pini,";"))== NULL)
{
strcpy(buffer," ");
}
pt3 = pout - pt1 ;
memset(buffer, 0, sizeof(buffer));
strncpy(buffer,pini,pt3-pt2);
}
result = (char *)malloc(strlen(buffer) + 1); /* +1 = DFTTZ! */
strcpy(result,buffer) ;
printf("result==>%s<==\n", result);
return result; //returning this => 7891150019508
}
The char *result2 and result3 are the variables I was using to store data if I recieve the "item;" in the line, and thats just a small part of the code, I actually created an if statement in every kinda of line I will recieve ("scanner;", "item;", "key;" and a few others).
Thank you very much for your attention and time Salem!