Created
December 29, 2021 10:37
-
-
Save goog/f41b7b7fcdb7e9de93606c370c9d22b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char *strtok(char *str, const char *delimiters) | |
{ | |
char *token = NULL; | |
static char *begin = NULL; | |
if(str != NULL) | |
{ | |
begin = str; | |
} | |
else | |
{ | |
if(begin == NULL) | |
return NULL; | |
} | |
char *p = begin; // scan begin location | |
//printf("p %p -%c-\n", p, *p); | |
while(*p) | |
{ | |
if(strchr(delimiters, *p) != NULL) | |
{ | |
*p = '\0'; | |
p++; | |
break; | |
} | |
p++; | |
} | |
token = begin; | |
if(*p == '\0') // reach original string ending | |
{ | |
begin = NULL; | |
} | |
else | |
{ | |
begin = p; // new begin | |
} | |
return token; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment