gotcha in strtok(3)

Karl Heuer karl at haddock.ISC.COM
Sat Feb 27 05:53:13 AEST 1988


In article <45 at vsi.UUCP> friedl at vsi.UUCP (Stephen J. Friedl) writes:
>I'd like to relate a gotcha that could drive you crazy.  We often use
>strtok(3) to run through a PATH-type variable to pick apart the individual
>pieces.  [But it scribbles in your array, which can be a problem.]

Another problem is that strtok() doesn't distinguish between "/bin:/etc" and
"/bin::/etc", so it's not really appropriate for parsing PATH or /etc/passwd.

For the above and other reasons, I never use strtok().

Karl W. Z. Heuer (ima!haddock!karl or karl at haddock.isc.com), The Walking Lint



More information about the Comp.lang.c mailing list