Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-winken!uunet!vsi!friedl From: friedl@vsi.COM (Stephen J. Friedl) Newsgroups: comp.lang.c Subject: Re: In defense of scanf() (Re: Re^2: scanf(..)) Summary: More problems with strtok() Message-ID: <1134@vsi.COM> Date: 18 Jun 89 19:16:51 GMT References: <225800176@uxe.cso.uiuc.edu> <11831@bloom-beacon.MIT.EDU> <824@cbnewsl.ATT.COM> Organization: V-Systems, Inc. -- Santa Ana, CA Lines: 31 In article <4563@ficc.uu.net>, peter@ficc.uu.net (Peter da Silva) writes: > I tend to stick with strspn() and strtok(), myself. In article <824@cbnewsl.ATT.COM>, mpl@cbnewsl.ATT.COM (michael.p.lindner) writes: > Hope you never have to do anything complex. If you call strtok on e string > in the middle of a strtok of another string it trashes its state information > on the first string (a little known feature), which can cause extremely > elusive bugs. In addition, strtok() considers multiple occurrences of the separating token to be one, so you can't use it for obvious things like parsing an /etc/passwd line. One more thing. If you use strtok to pick apart an environment variable, be sure to copy the environment string somewhere before you tear into it. We had a program whose child processes were always failing, and it drove us nuts until we realized that it was strtok again. We were picking apart $PATH earlier in the program, and since strtok places NULs in the string, the environment was getting corrupted for the child. Neither of these are bugs -- they are documented parts of the function -- but nevertheless we have been hit with these gotchas. Steve -- Stephen J. Friedl / V-Systems, Inc. / Santa Ana, CA / +1 714 545 6442 3B2-kind-of-guy / friedl@vsi.com / {attmail, uunet, etc}!vsi!friedl ---> vsi!bang!friedl <-- NEW "Friends don't let friends run Xenix" - me