Seperating the contents of a string into individual components.

Seperating the contents of a string into individual components.

Post by Norm Dresne » Tue, 04 Dec 2001 05:02:07




Quote:

> Cheez, man strtok() dudes.
> -SEan

    That may be the worst solution to the problem, but it's the most
popular.

    What's wrong with it?  Well, the worst problem is that it simply isn't
reentrant/recursive so you can't parse a sub-string while you're parsing the
main string.  Also, see below.
    It's not very difficult to write a reentrant replacement where each
context saves it's own data.  That is, of course, assuming that you don't
have a lot of parsing to do.  If you do, the lex/yacc family is probably the
most flexible parser generator in common use.

BTW, here's what the gcc man-page for this function says:

        Never use this function.  This function modifies its first
        argument.   The  identity  of  the delimiting character is
        lost.  This function cannot be used on constant strings.

Need I say more?

            Norm