#include <iostream>
#include <string.h>
using namespace std;
char *my_strtok(char *dist,const char *src)
{
static char *result;
char map[32];
const char *p = src;
memset(map,0,sizeof(map));
while (*p)
{
map[*p >> 3] |= (0x1 << (*p & 0x7));
p++;
}
char *q;
if (dist)
q = dist;
else
q = result;
while ((map[*q >> 3] & (1 << (*q & 0x7))) && *q)q++;
dist = q;
for (; *dist; dist++)
{
if (map[*dist >> 3] & (0x1 << (*dist & 0x7)))
{
*dist=' ';
dist++;
break;
}
}
result = dist;
return q;
}
int main()
{
char s[] = "abc efg hlk";
cout << my_strtok(s, " ") << endl;
cout<<my_strtok(NULL, " ")<<endl;
cout << my_strtok(NULL, " ") << endl;
return 0;
}