I want to make a code that searches a text file and finds a certain string, and then changes that string to another string. First im going to have it input the whole file, and i am couting it too, so that i can make sure it worked. But it doesn't cout anything and the text file changes to a bunch of random characters. Anyone know how to fix this? This is my code so far:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
char File[150], re[4], line[100][125];
string response;
int counter=0;
cout<<"Would you like to convert a SRL 3.81 script to SRL 4? (yes or no) \n";
cin>>re;
strupr(re);
response=re;
if(response== "YES") {
cout<<"Please enter the name of the file (C:/Program Files/example.txt)"<<endl;
cout<<"the location is not needed if this program and the script are in the same folder\n";
cin.ignore ( 150, '\n' ); //flush the input stream
cin.getline(File, 150);
cout<<"Now Editing "<< File<<endl;
ifstream fin;
ofstream fout;
fout.open(File);
fin.open(File);
while (!fin.eof()){
fin.getline(line[counter], 125);
counter++;
}
for(counter=0; counter<10; counter++){
cout<<line[counter]<<endl;
}
fin.close();
fout.close();
}
else if(response == "NO"){
cout<<"Closing Program...\n";
}
else{
cout<<"Response not understood. Closing Program...\n";
}
system("PAUSE");
return 0;
}