Originally Posted by
pokks
Hi,
I'm using strtok to parse the a string using '|' as the delimiter...It worked fine as long as none of the fields were empty, i.e. text1|text2|text3 worked, but text1||text3 did not. It skipped text2 and returned text3.
could anyone please help me out with this problem..is ther any way to solve it?? how to capture null in field using strtok.?? ur help will be greatly appreciated
thanks in advance
pokks.
You could write strok2()
Code:
char *strtok2 (char *Str, const char *Del)
{
static char *OldStr = NULL;
char *Ptr;
if (Str == NULL)
if (OldStr == NULL)
return NULL;
else
Str = OldStr;
if (Str [0] == '\0') return NULL;
Ptr = Str;
while (*Ptr != '\0' && !IsDelim (*Ptr, Del))
Ptr++;
if (*Ptr != '\0') {
*Ptr = '\0';
OldStr = Ptr + 1;
return Str;
} else {
OldStr = NULL;
return Str;
}
}