home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19206 < prev    next >
Encoding:
Internet Message Format  |  1993-01-04  |  1.8 KB

  1. Path: sparky!uunet!spool.mu.edu!olivea!hal.com!parlo.hal.COM!not-for-mail
  2. From: paul@hal.COM (Paul Sander)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: strtok
  5. Message-ID: <1iab2aINNlmn@parlo.hal.COM>
  6. Date: 4 Jan 93 21:43:38 GMT
  7. References: <1992Dec31.045902.2025@mcs.drexel.edu> <bibhas.725836376@femto.engr.mun.ca>
  8. Distribution: usa
  9. Organization: HaL Computer Systems, Inc.
  10. Lines: 30
  11. NNTP-Posting-Host: parlo.hal.com
  12.  
  13. In article <bibhas.725836376@femto.engr.mun.ca> bibhas@femto.engr.mun.ca (Bibhas Bhattacharya) writes:
  14. >tjhendry@mcs.drexel.edu (Jonathan Hendry) writes:
  15. >
  16. >>Hi. Could someone please email me a brief description of how to use
  17. >>strtok()? I have read a few books, and asked my coworkers, and haven't
  18. >>received much useful information.
  19. >
  20. >>Namely, after I run it on a string once, how do I get to the next
  21. >>part of the string?
  22. >
  23. >It's worth noting that the string returned by strtok is not a fresh copy
  24. >but a part of the fragmented original string. Which means:
  25.  
  26. [example deleted]
  27.  
  28. It's also worth noting that strtok keeps global state, which means that it
  29. is not reentrant.  Since strtok is usually used for some kind of loop variant,
  30. you must be careful never to call strtok again from inside the loop.  When
  31. your loop calls another function that calls another function that calls
  32. strtok, you have a bug that is quite difficult to track down.
  33.  
  34. Robert Osborne posted a strtok replacement to comp.lang.c on September 12,
  35. 1991 that returns strtok's global state in a parameter to the caller, making
  36. it reentrant.  The message-ID is 1395@isgtec.UUCP, and I have copies of it
  37. if anyone is interested.
  38. -- 
  39. Paul M. Sander  (408) 379-7000  |  "If everything were easy, where would be
  40. HaL Computer Systems, Inc.      |   the challenge?"
  41. 1315 Dell Avenue                |
  42. Campbell, CA  95008  USA        |
  43.