I don't have my compiler to try the following function, but I think there are some problems in it anyway. See comments.
Code:
void findTokens(char* theString, char **ptr, char colon)
{
int index=0;
ptr[index++] = theString;
//you can't assign one Cstyle string to another, use strcpy() instead
//each ptr[index] needs to have memory declared. You need another loop with call to new operator to do this, probably back in main()
//you don't want to assign the entire length of theString to ptr[0] either, you want just the firtst token from theString in ptr[0]
while(*theString)//this looks for the null char at end of theString
{
if(*theString == colon)//this looks for a colon in the theString
{
*theString = '\0';//this replaces the colon with a null char
ptr[index++] = (theString + 1);
//this assigns theString, minus the current token to the next string in ptr, but it doesn't leave just the first token in ptr[index]; it leaves whatever theString was when theString was passed to ptr[index] in ptr[index] so:
ptr[0] will be "abcd0001:groupno:userno:name:/bin/ksh"
ptr[1] will be "groupno:userno:name:/bin/ksh"
ptr[2] will be "userno:name:/bin/ksh"
etc.
}//end if
theString++;
}//end while
return;
I hope that I have my thinking cap on correctly this AM, but sometimes it comes off when I am not looking, so use a compiler to try out the function---don't take me at my word.
If I am correct here's my algorithm for finding tokens and storing one token per string in ptr.
I would declare a tempString and use a different counter variable to keep track of where I am in tempString.
I would read each char into tempString from theString until I found a colon.
I would place a nul char in tempString instead of a colon
I would then assign tempString to ptr[index++]
I would then reset the counter variable for tempString to 0.
I would then move on to the next char in theString.