There is a subtle mistake in the while loop. You call strtok and then print out the result, but you do not check if the pointer is null before using cout with the pointer.

Compare your code to the...