Hello
Thanks for the help people.
The code is working great but just one thing.
Code:
#include<stdio.h>
#include<stdlib.h>
char* teste(char* s)
{
char *tok = (char *)malloc(3);
char *p;
int i;
p=(char *)strtok(s," ");
for (i = 0; p && i < 3; i++) {
tok[i] = *p;
p = (char *)strtok(NULL," ");
}
/*if (i < 3) {
fprintf(stderr,"Parametros em falta\n");
return -1;*/
return tok;
}
int main()
{
char op[]="p 1 2";
//teste(op);
char *comando=teste(op);
printf("COMANDO1: %c",comando[0]);
}
With this code the return is an single char. if i change the op=" cr test" it will only return "c" and i need to return "cr" and "test".
There are many op:
"p 1 1" - return p and 1 and 1
"vp" - return only vp
"cr test" - return cr and test
So can how can i change the code for working nice ? making some changes on this:
Code:
char *tok = (char *)malloc(3);
to:
Code:
char *tok[3]= (char *)malloc(3);