If "i" doesn't increment, that's the nature of strtok and I don't see much you can do about it other that writing your own function, which shouldn't be too hard.
Since you were using strtok, it doesn't matter if you destroy the original string in the process, so something like this:
Code:
#include <stdio.h>
int main() {
char string[]="a:b::c:d",
*array[10]; /* POINTERS */
int count=0, index=1;
array[0]=string;
while (string[count]!='\0') {
if (string[count]==':') {
array[index]=&string[count+1];
index++;
string[count]='\0';
}
count++;
}
/* now verify */
for (count=0; count<index; count++) {
printf("element #%d: \"%s\"\n",count,array[count]); }
return 0;
}
Output:
element #0: "a"
element #1: "b"
element #2: ""
element #3: "c"
element #4: "d"
Even though the original string is chopped up in this, you need to keep it since "array" is only pointers (or you could use strcpy). Etc.