Among other things, your while loop end condition is wrong. You're checking pch[j + 1]
which is always uninitialized memory, causing the loop to continue unpredictably until you encounter a zero in memory which may cause the loop to stop.
On an alternate note, I highly discourage the use of strtok
in C++, due to its string-destruction. Boost has a quite nice string parsing facility, and even in the base C++ language it's simple enough to do most parsing with built in string functionality.