You can try this function, to see if it can makes the work:
Code:
#include <stdio.h>
void gettoken(char *inbuf, char *outbuf, char delim)
{
static char *pNext = inbuf; //first points to the string, after to next tokens
int i;
for (i=0; (*pNext != delim) && (*pNext != '\0'); pNext++,i++)
outbuf[i] = *pNext;
//check if we are in last token
if (*pNext++ == '\0')
pNext = inbuf;
outbuf[i] = '\0'; //put null to close string
}
int main(void)
{
char inbuf[] = "One|Two|Three";
char outbuf[100];
int i;
//get first three tokens and print them
for (i=0; i<3; i++)
{
gettoken(inbuf, outbuf, '|');
puts(outbuf);
}
//now check if the function knows how to restart to first token
gettoken(inbuf, outbuf, '|'); //this should put in outbuf 'one'
puts(outbuf);
return 0;
}
It's real simple it contains a static pointer that points to the next token to be getted, if is the last token, it points to the first one again.