Modify the condition of the inner while:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char c; //declare variable c of type char
int count = 0; //declar variable count of type int and initializes to 0
ifstream infile( "input.txt" ); //opens file input.txt for reading
ofstream outfile( "output.txt" ); //opens file output.txt for writing
c = infile.get(); //gets first character from infile and assigns to variable c
//while the end of file is not reached
while ( !infile.eof() )
{
//while loop that counts the number of characters until a space is found
while( c != ' ' && !infile.eof() )
{
count++; //increments counter
c = infile.get(); //gets next character
}
c = infile.get(); //gets next character
outfile << count << " "; //writes space to output.txt
count = 0; //reset counter
}
//closes files
infile.close();
outfile.close();
return 0;
}