/* The following program deletes every occurance 
 of string s2 in a file whose name is 
 entered by the user. Here we ignore case. 
 Also we'll assume strings don't wrap 
 from one line to the next.
*/
#include <iostream>
#include <string>
using namespace std;
string toupper(string s);
void deleteFromFile(string fileName, string outputFileName, string s2);
int main()
{
	string inputFileName, outputFileName, s2;
	cout << "Enter the string to be deleted: " << endl;
	cin >> s2;
	cout << "Enter the name of the file from which the string has to"
		<< " be deleted: " << endl;
	cin >> inputFileName;
	cout << "Enter the name of the output file: " << endl;
	cin >> outputFileName;
	deleteFromFile(inputFileName,outputFileName,s2);
	return 0;
}

string toupper(string s)
{
	int i, n = s.size();
	for (i = 0; i < n; i++)
		s[i] = toupper(s[i]);
	return s;
}

#include <fstream>
void deleteFromFile(string inputFileName, string outputFileName, string s2)
{
	int n2, i, pos, count = 0;
	string t1, t2, s1, s3 = "";
	ifstream inFile;
	ofstream outFile;
	inFile.open(inputFileName.c_str());
	if (!inFile)
	{
		cout << "Can't open the file." << endl;
		exit(1); // Use exit here because this is a void function
				// You can't use return 1 here, but you 
				// can use just return
	}
	outFile.open(outputFileName.c_str());
	getline(inFile,s1);
	while (inFile)
	{
		n2 = s2.size();
		t2=toupper(s2);	
		i = 0;
		while (i < s1.size()) // Note the size of s1 may keep changing
		{
			t1 = toupper(s1);
			pos = t1.find(t2);
			if (pos >= 0 && pos < s1.size())
			{
				s1.replace(pos,n2,s3);
			}
			i++;
		}
		outFile << s1 << endl;
		getline(inFile,s1);
	}
}
