15.12.2009, 15:33
It may be even better if we will use static variable to hold the start of the next word:
So we don't need to create a separate variable somewhere outside of function each time to store the index...
pawn Код:
stock strtok(const source[], dest[], separator = ' ', start = -1)
{
if (!source[0])
{
return 0;
}
new
i,
ch;
static
j;
if (start == 0)
{
j = 0;
}
else if (start > 0)
{
j = start;
}
while ((ch = source[j++]))
{
if (ch != separator)
{
dest[i] = ch;
i++;
}
else
{
while (source[++j] == separator) {}
break;
}
}
dest[i] = '\0';
return i;
}