Maybe you could check if the character is a space before you print it?

And don't use gets! FAQ > Why gets() is bad / Buffer Overflows - Cprogramming.com