Write a program that reads text from one file and writes an edited version of th
ID: 3837010 • Letter: W
Question
Write a program that reads text from one file and writes an edited version of the same text to another file. The edited version is identical to the un- edited version except that every string of two or more consecutive blanks is replaced by a single blank. Thus, the text is edited to remove any extra blank characters. Your program should define a function that is called with the input- and output-file streams as arguments. If this is being done as a class assignment, obtain the file names from your instructor. in C++
Explanation / Answer
Wrote a simple c++ program as below:
#include <iostream>
#include <fstream>
using namespace std;
void processFile( ifstream &input, ofstream &output )
{
string word;
string delimiter = "";
while(input >> word)
{
output << delimiter << word;
delimiter = " ";
}
}
int main()
{
ifstream input;
input.open ("input.txt");
ofstream output;
output.open ("output.txt");
processFile(input, output);
input.close();
output.close();
return 0;
}
For this to run.. Just keep the input data in input.txt file in same directory.. and it will run and create the output,txt file with correct output in same directory.
input.txt:
My Name is Ramm. I am aj djdb ddd.
output.txt:
My Name is Ramm. I am aj djdb ddd.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.