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