This is a very simple example. One of the biggest things about strtok() that has screwed this noder up is that subsequant calls to strtok() must have the first argument set to NULL. When no more tokens can be found in the string, NULL is returned.

Each occurance of characters in the string 'tokens', in this case 's' and '\n', is removed from the string 'buffer' and the characters between them is returned as a character pointer. Note that the first call is made with 'buffer' as the first argument, but later calls (in the do{}while() loop) are made with NULL as the first argument. If this wasn't done, the first token would always be returned!

The only time when this function will have problems is if you are doing parsing within parsing. If you parse out a token from a string, and then try to use strtok() on that token (while still in the loop through the original string), Bad Things happen. This is because strtok() uses a static buffer for it's parsing. The same applies to multi-threaded applications using this function. If you are going to have the possibility of this happening, use strtok_r(), which is thread safe, instead.