Hi guys, I've got troubles with a conversion.
My function:
void stringFormat (char *input, int nums)
receives a string like this:
"name;3,45,5,6,77;"
and a number indicating how many numbers in the String (in this case 5)
I've got to tokenize the string in order to obtain:
1) a string named data: "name"
2) an array of int made of the numbers received: numbers[0]=3; numbers[1]=45; and so on 'til 77
Here's my wrong solution:
void stringFormat(char *input, int nums){
char *data;
int *numbers[nums];
int i=0;
char *p;
p = strtok (input,";");
if(p != NULL) data=p;
p = strtok (NULL, ",;");
while (p != NULL)
{
numbers[i] = p;
i++;
p = strtok (NULL, ",;");
}
i=0;
/* I check array content */
while (i<(nums)){
printf("%d\n", *(numbers[i]) );
i++;
}
}
...any suggestion will be highly appreciated !!