Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char *my_strtok_r(char *text, const char *delimitor, char **save_this)
- {
- int nLen = 0;
- if (delimitor == NULL) {
- return NULL;
- }
- nLen = strlen(delimitor);
- if (nLen <= 0) {
- return NULL;
- }
- if(save_this == NULL)
- {
- return NULL;
- }
- if (text != NULL)
- {
- /* New text. */
- int i = 0;
- while(text[i] != '\0')
- {
- if(strncmp(text+i, delimitor, nLen) == 0)
- {
- text[i] = '\0';
- *save_this = &text[i + nLen];
- //printf("[%s:%s:%d] i=%d, return save_this=0x%p\n", __FILE__, __func__, __LINE__, i, *save_this);
- return text;
- }
- i++;
- }
- }
- else if ((save_this != NULL) && (*save_this != NULL))
- {
- /* Old text. */
- int i = 0;
- char *start = *save_this;
- while((*save_this)[i] != '\0')
- {
- //printf("[%s:%s:%d] i=%d, *save_this[%d]=[%c]\n", __FILE__, __func__, __LINE__, i, i, (*save_this)[i]);
- if(strncmp(*save_this+i, delimitor, nLen) == 0)
- {
- (*save_this)[i] = '\0';
- *save_this = &((*save_this)[i + nLen]);
- //printf("[%s:%s:%d] i=%d, return start=0x%p\n", __FILE__, __func__, __LINE__, i, start);
- return start;
- }
- i++;
- }
- *save_this = NULL;
- save_this = NULL;
- return start;
- }
- return NULL;
- }
Add Comment
Please, Sign In to add comment