Name: Anonymous 2012-11-07 22:14
I'm trying to write a program that edits a text file to replace all consecutive spaces with a single space. The editing of the spaces is what's giving me problems.
}
while(! fin.eof())
{
fin.get(next);
if(isspace(next))
count = count + 1;
if(isspace(next) && count >= 2)
{
fout << ' ';
count = 0;
}
else
{
fout << next;
count = 0;
}
}
fin.close( );
fout.close( );
}
Basically, I'm trying to add 1 every time a space is encountered as some sort of comparison, when it's = 2 it gets replaced with single space. So far it outputs the text unedited. Any help would be appreciated.
}
while(! fin.eof())
{
fin.get(next);
if(isspace(next))
count = count + 1;
if(isspace(next) && count >= 2)
{
fout << ' ';
count = 0;
}
else
{
fout << next;
count = 0;
}
}
fin.close( );
fout.close( );
}
Basically, I'm trying to add 1 every time a space is encountered as some sort of comparison, when it's = 2 it gets replaced with single space. So far it outputs the text unedited. Any help would be appreciated.