Can anyone see what is wrong with this?
insertCode:
#include <string>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <algorithm>
using namespace std;
class toLower {public: char operator()(char c) const {return tolower(c);}};
int main()
{
const int MAX_EMAILS = 1000;
int nEmails = 0;
string email[MAX_EMAILS];
string ifile;
cout << "Enter the name of the file to be opened: ";
getline(cin, ifile);
ifstream fin;
fin.open(ifile.c_str());
if(!fin.good()) throw "I/O error";
if(ifile.empty())
fin.open("fileContainingEmails.txt");
string line;
string anEmail;
string a;
string b;
int i, s, e;
while(getline(fin, line))
{
for (i = 0; i < line.length(); i++)
{
if (line[i] == '@')
{
s = i - 1;
if(s < 0) break;
bool valid1 = false;
if(line[s] >= 'a' && line[s] <= 'z')valid1 = true;
if(line[s] >= 'A' && line[s] <= 'Z')valid1 = true;
if(line[s] >= '0' && line[s] <= '9')valid1 = true;
if(line[s] == '_' || line[s] == '+' || line[s] == '-')valid1 = true;
if(valid1 == true)s--;
if(vaild1 == false)break;
e = i + 1;
if(e >= line.length()) break;
if(line[e] >= 'a' && line[e] <= 'z')valid1 = true;
if(line[e] >= 'A' && line[e] <= 'Z')valid1 = true;
if(line[e] >= '0' && line[e] <= '9')valid1 = true;
if(line[e] == '_' || line[e] == '+' || line[e] == '-')valid1 = true;
if(valid1 == true)e++;
if(vaild1 == false)break;
bool hasdot = false;
if(line[i] == '.')hasdot = true;
if(s < i && i < e && hasdot)
anEmail = line.substr(s, (e - s) + 1);
a = anEmail;
transform(a.begin(), a.end(), a.begin(), toLower());
bool found = false;
for (int i = 0; i < nEmails; i++)
{
b = email[i];
transform(b.begin(), b.end(), b.begin(), toLower());
if(a == b)
if(found == true)break;
}
if (!found && nEmails < MAX_EMAILS)
email[nEmails++] = anEmail;
}
}
}
fin.close();
cout << endl;
cout << nEmails << " email addresses were found in the input file" << endl;
cout << endl;
ofstream fout;
if(nEmails > 0)
{
string ofile;
cout << "Where are these email addresses to be sent: ";
getline(cin, ofile);
fout.open(ofile.c_str());
for(i = 0; i < nEmails - 1; i++)
{
fout << email[i] << ";" << " " << endl;
}
fout << email[nEmails -1] << endl;
if(ofile.empty())
fout.open("copyPasteMyEmails.txt");
for(i = 0; i < nEmails - 1; i++)
{
fout << email[i] << ";" << " " << endl;
}
fout << email[nEmails -1] << endl;
}
fout.close();
return 0;
}