Quote:Original post by antiquechronoQuote:
3) Even strtok()'s own documentation says never to use it.
Where is your source?
Um, strtok()'s own documentation. If you're on a Unix-compatible system, try 'man strtok'. Otherwise, try googling that. Third hit for me.
Quote:(Emphasis mine)
BUGS
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.
It's actually right there, literally, for many implementations.
Of course, there would be plenty of reason not to use it in C++ anyway: it's yet another function treating null-delimited sequences of text as somehow special, instead of supporting an actual string type.
Incidentally, the null-delimited approach to string representation is pretty brain-dead. Compared to the main not-a-real-string-type alternative - "raw Pascal strings", where a length count is stored at the beginning of the string, they are never any better algorithmically, prevent you from including nulls in the string text (which is useful for some applications), and generally speaking, save a whopping three bytes of memory. (It's possible to encode the length count as a variable length integer, squeezing things out even more, while adding at most constant overhead to each operation.) This string representation was chosen by the C language implementors back in the 70s, when those three bytes were important (and when optimizing compilers might have not gotten the same or better performance out of a loop over array indices as a loop while characters are non-zero). It's ancient and barbaric and really should be forgotten.