Consider using a flag to keep track of whether you're in a sequence of white space or not. Don't print anything until you are out of the sequence.

If that's not enough of a hint, it helps with...