nanolucifer said:
I just gave him an example of how strtok works. Checking for the right
number of periods shouldn't be too hard
strtok() isn't a great choice for checking for the right number
of delimiters, because it considers multiple consecutive
delimiters to be the same as single delimiters. That is, it will
tokenize "1.2.3.4" and ".1..2...3....4....." the same way.
strtok() has at least these other problems:
* It modifies the string that it tokenizes. This is bad
because it forces you to make a copy of the string if
you want to use it later. It also means that you can't
tokenize a string literal with it; this is not
necessarily something you'd want to do all the time but
it is surprising.
* It can only be used once at a time. If a sequence of
strtok() calls is ongoing and another one is started,
the state of the first one is lost. This isn't a
problem for small programs but it is easy to lose track
of such things in hierarchies of nested functions in
large programs. In other words, strtok() breaks
encapsulation.