Subj : Re: STRTOK Question To : borland.public.cpp.borlandcpp From : maeder@glue.ch (Thomas Maeder [TeamB]) Date : Wed Sep 03 2003 07:22 pm Steven writes: > Is the first line of output a result of strtok, printf, or is strtok > being misused? strtok is misused. When tokenizing a string, the first call to strtok should pass the string's address as first argument, while subsequent calls should pass 0. But the evaluation of function arguments (printf in your snippet) is unspecified, so we can't tell which of the four calls is the first one. More, strtok works with a static internal buffer. This means that if you want to use it, you should 1. call strtok, passing the string's address as first argument 2. evaluate the result, copy it if it is to be used after the next call of strtok 3. call strtok, passing 0 as first argument 4. evaluate the result, copy it if it is to be used after the next call of strtok 5. continue with 3. until strtok returns 0 or until you have found what you were after > Why does the second line of output produce 3 (null) values? Because strtok is misused. BTW: the strtok man page on my workstation says (among other things) about atrtok and strtok_r: "Never use these functions." .