home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / c / 19095 < prev    next >
Encoding:
Text File  |  1992-12-31  |  1.6 KB  |  41 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!usc!cs.utexas.edu!torn!csd.unb.ca!news.ucs.mun.ca!femto.engr.mun.ca!bibhas
  3. From: bibhas@femto.engr.mun.ca (Bibhas Bhattacharya)
  4. Subject: Re: strtok
  5. Message-ID: <bibhas.725836376@femto.engr.mun.ca>
  6. Sender: usenet@news.ucs.mun.ca (NNTP server account)
  7. Organization: Memorial University of Newfoundland
  8. References: <1992Dec31.045902.2025@mcs.drexel.edu>
  9. Distribution: usa
  10. Date: Thu, 31 Dec 1992 21:12:56 GMT
  11. Lines: 28
  12.  
  13. tjhendry@mcs.drexel.edu (Jonathan Hendry) writes:
  14.  
  15. >Hi. Could someone please email me a brief description of how to use
  16. >strtok()? I have read a few books, and asked my coworkers, and haven't
  17. >received much useful information.
  18.  
  19. >Namely, after I run it on a string once, how do I get to the next
  20. >part of the string?
  21.  
  22. It's worth noting that the string returned by strtok is not a fresh copy
  23. but a part of the fragmented original string. Which means:
  24.     - If you're going to refill the original string and want to use
  25.     the returend string later, better make a copy of the returned
  26.     string somewhere.
  27.         gets(line);
  28.         tok = strtok(line,":");
  29.         gets(line); /*refill*/
  30.         /*guess what? tok is not what you think it is, anymore*/
  31.  
  32.     - As strtok operates on a string it keeps on fragmenting it. If you want
  33.     to do anything with original string again, you must keep a copy of it.
  34.  
  35. Bibhas.
  36. --
  37.     +==========================+=========================+
  38.     | login name: DR. Jackyl   |  In real life: Mr. Hyde.|
  39.     +==========================+=========================+
  40.                   bibhas@pico.engr.mun.ca  
  41.