Guest User

Untitled

a guest
Jul 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. char *my_strtok_r(char *text, const char *delimitor, char **save_this)
  2. {
  3. int nLen = 0;
  4.  
  5. if (delimitor == NULL) {
  6. return NULL;
  7. }
  8.  
  9. nLen = strlen(delimitor);
  10. if (nLen <= 0) {
  11. return NULL;
  12. }
  13.  
  14. if(save_this == NULL)
  15. {
  16. return NULL;
  17. }
  18. if (text != NULL)
  19. {
  20. /* New text. */
  21. int i = 0;
  22. while(text[i] != '\0')
  23. {
  24. if(strncmp(text+i, delimitor, nLen) == 0)
  25. {
  26. text[i] = '\0';
  27. *save_this = &text[i + nLen];
  28. //printf("[%s:%s:%d] i=%d, return save_this=0x%p\n", __FILE__, __func__, __LINE__, i, *save_this);
  29. return text;
  30. }
  31. i++;
  32. }
  33. }
  34. else if ((save_this != NULL) && (*save_this != NULL))
  35. {
  36. /* Old text. */
  37. int i = 0;
  38. char *start = *save_this;
  39. while((*save_this)[i] != '\0')
  40. {
  41. //printf("[%s:%s:%d] i=%d, *save_this[%d]=[%c]\n", __FILE__, __func__, __LINE__, i, i, (*save_this)[i]);
  42. if(strncmp(*save_this+i, delimitor, nLen) == 0)
  43. {
  44. (*save_this)[i] = '\0';
  45. *save_this = &((*save_this)[i + nLen]);
  46. //printf("[%s:%s:%d] i=%d, return start=0x%p\n", __FILE__, __func__, __LINE__, i, start);
  47. return start;
  48. }
  49. i++;
  50. }
  51. *save_this = NULL;
  52. save_this = NULL;
  53. return start;
  54. }
  55. return NULL;
  56. }
Add Comment
Please, Sign In to add comment