I have a string like "123-#-#-abc-user-#-#-abcpassword-#-#-123456", i need to split this string with pattern "-#-#-" to create an array. I used the following code to do this
char buf[5000];
strcpy(buf, "123-#-#-abc-user-#-#-abcpassword-#-#-123456");
int i = 0;
char *p = strtok (buf, "-#-#-");
char *array[5000];
int items = 0;
while (p != NULL)
{
items++;
array[i++] = p;
p = strtok (NULL, "-#-#-");
}
But the result isn't getting for "123-#-#-abc-user-#-#-abcpassword-#-#-123456" due to the hyphen in the "abc-user". What i am expecting is that array[0] has the 123, array[1] has abc-user, array[2] as abcpassword etc. Is there any other method to split to array with the exact pattern ?