Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to edit text files for extra blanks. The program will replace an

ID: 3770066 • Letter: W

Question

Write a program to edit text files for extra blanks. The program will replace any
string of two or more blanks with a single blank. Your program should work as
follows: Create a temporary file. Copy from the file to the temporary file but do not
copy extra blanks. Copy the contents of the temporary file back into the original
file. Use a method (or methods) in the class File to remove the temporary file.
You will also want to use the class File for other things in your program. The
temporary file should have a name that is different from all existing files so that
the existing files are not affected (except for the file being edited). Your program
will ask the user for the name of the file to be edited. However, it will not ask the
user for the name of the temporary file but instead will generate the name within
the program. You can generate the name any way that is clear and efficient. One
possible way to generate the temporary file is to start with an unlikely name, such
as "TempX" , and to append a character, such as 'X' , until a name is found that does
not name an existing file.

Explanation / Answer

this program will ask user to enter file name of user if that file is found it will open create TempXyz123.txt file and read all data from users file to temp file as well as removing unwanted blank.After that it will copy TempXyz123.txt file content back to original file and delete the TempXyz123.txt file.

<code>

#include<bits/stdc++.h>
using namespace std;
int main()
{
   ofstream temp,rtemp;
   temp.open ("TempXyz123.txt");
   ifstream input,rinput;
   char str[1000];
   scanf("%s",str);
   input.open(str);
   if (input.is_open()){
       string tmp;
       while(input >> tmp){
           temp << tmp;
           temp << " ";
       }
   }else{
       cout<<"file not found ";
   }
   input.close();
   temp.close();
   rtemp.open(str);
   rinput.open("TempXyz123.txt");
   string stmp;
   bool flag = true;
   while(rinput >> stmp){
       if(flag){
           rtemp << stmp;
           flag = false;
       }else{
           rtemp << " ";
           rtemp << stmp;
       }
   }
   rtemp.close();
   rinput.close();
   system ("rm TempXyz123.txt");
   return 0;
}

</code>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote