Write a program that reads text from one file and writes an edited version of th
ID: 3767468 • 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 unedited 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.Explanation / Answer
code:
#include <bits/stdc++.h>
using namespace std;
void f(ifstream& inf,ofstream& outf){
string s;
while(getline(inf,s)){
int l=s.length();
char pre='a';
for(int i=0;i<l;i++){
if(pre==' ' && s[i]==' '){
}
else{
pre=s[i];
outf<<s[i];
}
}
outf<<endl;
}
}
int main(){
ifstream inf;
inf.open("input.txt");
ofstream outf;
outf.open("output.txt");
f(inf,outf);
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.