Aha! That fixed it. How stupid of me. Why a missing \0 at the end of the third substring should affect the second, I'm not sure.

Thanks everyone.

05-26-2010

laserlight

Quote:

Originally Posted by TheBigH

Why a missing \0 at the end of the third substring should affect the second, I'm not sure.

One possibility is that that the position of s is before that of m in memory. strtok() writes to m, and then to s. But due to the lack of space for the null terminator, there is buffer overflow, and the null terminator is written to m[0], thus turning m into an empty string.

05-26-2010

TheBigH

That makes a lot of sense, and would explain why you couldn't replicate the error: it's essentially random where the character arrays are stored so your m and s might have been in the other order.