Posted By

mwb1100 on 07/12/09


Tagged

domain public


Versions (?)

strtok_r


 / Published in: C
 

  1. /*
  2.  * public domain strtok_r() by Charlie Gordon
  3.  *
  4.  * from comp.lang.c 9/14/2007
  5.  *
  6.  * http://groups.google.com/group/comp.lang.c/msg/2ab1ecbb86646684
  7.  *
  8.  * (Declaration that it's public domain):
  9.  * http://groups.google.com/group/comp.lang.c/msg/7c7b39328fefab9c
  10.  */
  11.  
  12. char* strtok_r(
  13. char *str,
  14. const char *delim,
  15. char **nextp)
  16. {
  17. char *ret;
  18.  
  19. if (str == NULL)
  20. {
  21. str = *nextp;
  22. }
  23.  
  24. str += strspn(str, delim);
  25.  
  26. if (*str == '\0')
  27. {
  28. return NULL;
  29. }
  30.  
  31. ret = str;
  32.  
  33. str += strcspn(str, delim);
  34.  
  35. if (*str)
  36. {
  37. *str++ = '\0';
  38. }
  39.  
  40. *nextp = str;
  41.  
  42. return ret;
  43. }

Report this snippet  

You need to login to post a comment.