I'm kinda new in C so i need help.
I need to split a string to string array with the delimiter "&&",
the thing is that i tried to use strtok
, but when i use it, it looks like that the strtok
can't handle correctly if the is '&' some where in the string.
I know that each part between the && is at max 256 chars and that there are at most 16 parts.
so i need to create an array arr[16][256]
or an array of size 16*256.
in any case each time i try my code fail on the different between & and &&
example:
char arr[16][255];
char stringToSplit = "Hello World && How are u doing && more words & bla &";
output:
arr[0] = "Hello World ";
arr[1] = " How are u doing ";
arr[2] = " more words & bla &";
Thanks ahead!
This is what i tried:
int i;
char *p;
i = 0;
p = strtok (stringToSplit ,"&&");
while (p != NULL)
{
arr[i++] = p;
p = strtok (NULL, "&&");
}
for (i=0;i<16; ++i)
printf("%s\n", arr[i]);