1.

Polina Raj has used a text editing software to type some text in an article. After saving the article as MYNOTES.TXT, she realized 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.TXTThe function PURETEXT() should display the following content:

Answer»

void PURETEXT()

{

fstream fpl;

fpl. open("MYNOTES.txt", ios::in | ios::out): 

if(!fpl)

{

cout<<"Cannot open file"<<end1;

exit (0);

}

char ch;

char c;

while(!fpl.eof())

{

c=fpl.get();

if(c=='K')

{

fpl.seekg(-1, ios::cur);

fpl.put('C'):

}

}

fp1.clear();

fp1.seekp(0, ios::beg);

cout<<"\n After replacing character\n"); 

while(!fpl.eof())

{

fp1.get(ch);

cout<<ch;

fpl.close();

}



Discussion

No Comment Found

Related InterviewSolutions