I'm doing a program, and trying to find the @, going back to the beginning to search for valid characters, and when I find an invalid one I move it forward to valid one. Same goes for the end, except just leaving it at the invalid character. My program compiles, however after it takes the input and output files, it just sits there. Nothing appears after it tells me my input and output files. I can't figure out why.
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
class toLower{public: char operator() (char c) const {return tolower(c) ;}};
bool isValidCharacter(char c)
{
bool validCheck = false;
if ((c>='A' && c<= 'Z') || (c>='a' && c<='z') || (c>='0' && c<='9') || (c=='.') || (c=='-') || (c=='+'))
validCheck = true;
return validCheck;
}
int main()
{
ifstream fin;
string inputFile;
string outputFile;
string defaultInput = "fileContainingEmails.txt";
string defaultOutput = "copyPasteMyEmails.txt";
cout << "Enter input filename[default: fileContainingEmails.txt]: ";
getline(cin, inputFile);
if (inputFile.length() == 0)
{
inputFile = defaultInput;
outputFile = defaultOutput;
cout << "Enter output filename[default: copyPasteMyEmails.txt]: ";
getline(cin,outputFile);
if (outputFile.length() == 0)
outputFile = defaultOutput;
}
else
{
string c;
cout << "Enter output filename[default: " << inputFile << "]: ";
getline(cin, c);
if (c.length() == 0)
outputFile = inputFile;
else
outputFile = c;
}
cout << "Input file: " << inputFile << endl;
cout << "Output file: " << outputFile << endl;
fin.open(inputFile.c_str());
if (!fin.good()) throw "I/O error";
string emails;
int i;
while(getline(fin,emails))
{
for(i = 0; i < emails.length(); i++)
{
if(emails[i] == '@')
{
int s = i;
for(s; s <= emails.length(); s--)
{
if (s < 0) break;
if (isValidCharacter(emails[s]) == false)
{
s++;
if(isValidCharacter(emails[s]) == true) break;
}
}
bool hasDot = false;
int e = i;
for(e; e <= emails.length(); e++)
{
if(e = emails.length()) break;
if(isValidCharacter(emails[e]) == false) break;
if(e == '.')
hasDot = true;
}
if((s<i) && (e>i) && (hasDot == true))
cout << emails << endl;
}
}
}
cout << endl;
return 0;
}