If you read until you encounter a space then add one to the count and continue reading until a non-space character is encounterer and then continue your regular loop. Something like this pseudo code:
Code:
while (not end of file)
{
Get a character
write a character
if ( ' ' == character )
{
add one to word count;
do
{
get a character
write a character
}while( ' ' == character || '\r' == character ||
'\n' == character )
}
}
I've added another boundary condition if you run into the end of a line (carriage return ('\r') and line feed ('\n') they don't count as a word new word. This is for the case where the start of the next line is a space. You also need to put in logic to catch end of file while reading for non space characters.