#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void check_blank(ifstream& instream, ofstream& outstream);// a function to delete space
int main()
{
ifstream instream;
ofstream outstream;
instream.open("lines.txt"); //Open file: text to be edited
outstream.open("linesout.txt"); //Open file: edited text will go
check_blank(instream, outstream);
system("PAUSE");
instream.close(); //Close both files
outstream.close();
return 0;
} //End main
void check_blank(ifstream& instream, ofstream& outstream)
{
char a;
int count = 0;
int words = 0;
while(! instream.eof()) //While the file isn't at the end
{
instream.get(a);
if(a == ' ')
{
count++;
if(count >= 2) //If there are 2 or more spaces then do this
{
outstream <<' ';
count = 0; //reset count
}
}
else
{
outstream << a;
}
if ( a == ' ' || a == '\n' || a == '\t' )
{
words++;
}
}
cout<< "The number of words are: "<<words<<endl;
}
Attached File(s)
-
lines.txt (1.71K)
Number of downloads: 24 -
linesout.txt (2K)
Number of downloads: 35
This post has been edited by StormRonin: 10 March 2011 - 01:11 PM

New Topic/Question
Reply




MultiQuote



|