Polina Raj has used a text editing software to type some text in an article. After saving the article as MYNOTES.TXT, she realised that she has wrongly typed alphabet K in place of alphabet C everywhere in the article.
Write a function definition for PURETEXT() in C++ that would display the corrected version of the entire article of the file MYNOTES.TXT with all the alphabets “K” to be displayed as an alphabet “C” on screen.
Note: Assuming that MYNOTES.TXT does not contain any C alphabet otherwise.
Example:
If Polina has stored the following content in the file MYNOTES.TXT:
I OWN A KUTE LITTLE KAR.
I KARE FOR IT AS MY KHILD.
The function PURETEXT() should display the following content:
I OWN A CUTE LITTLE CAR.
I CARE FOR IT AS MY CHILD.
void PURETEXT()
{
fstream fp1;
fp1. open('MYNOTES.txt', ios::in | ios::out);
if(!fp1)
{
cout<<'Cannot open file'<<endl;
exit(0);
}
char ch;
char c;
while(!fp1.eof())
{
c=fpl.get();
if(c= ='K')
{
fp1.seekg(–1, ios::cur);
fp1.put('C');
}
}
fp1.clear();
fp1.seekp(0, ios::beg);
cout<<'\nAfter replacing character\n';
while(!fp1.eof())
{
fp1.get(ch);
cout<<ch;
}
fp1.close();
}