#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
usingnamespace std;
bool validation (char c)
{
bool result = false;
if ( (c >='A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <='9') || c =='.'||c =='-' || c =='+')
{ result = true; }
return result;
}
int main () {
//bool ValidEmailCharacters;
string lineFromFile;
int locationOfAtSign = -1;
int beforeatsign;
int afteratsign;
string InputfileName;
string OutputFileName;
string defaultInputFile = "fileContainingEmails.txt";
string defaultOutputFile = "copyPasteMyEmail.txt";
ifstream fin;
ofstream fout;
cout << "Enter your Input file name (ENTER for Default): " ;
getline (cin, InputfileName);
if (InputfileName.length() < 2) {
InputfileName = defaultInputFile;
}
fin.open (InputfileName);
cout << "Enter your Output file name (ENTER for Default): " ;
getline (cin, OutputFileName);
if (OutputFileName.length() < 2) {
OutputFileName = defaultOutputFile;
}
fout.open (OutputFileName);
// Read a line from the input file
while (!fin.eof()) //reads until end of file
{
//
fin >> lineFromFile;
if (!fin.good()) break;
cout << lineFromFile << "////////////////////////////////////////////////////////////////////////// "<< endl;
// process the line
for (int i = 0; i < lineFromFile.length(); i++)
{
if (lineFromFile[i] == '@')
{
locationOfAtSign = i;
cout << "Test1-Found at sign" << endl;
}
}
//checking at left of at sign
for(beforeatsign = locationOfAtSign-1; beforeatsign >= 0; beforeatsign--)
{
if (lineFromFile[beforeatsign] == 'x') break;
cout << "Test2- check to left of the at sign" << endl;
if (validation(lineFromFile[beforeatsign]) == false) break;
}
cout << "validating" << endl;
// checking to the right of the at sign
for (afteratsign = locationOfAtSign+1; afteratsign < lineFromFile.length(); afteratsign++)
{
if (lineFromFile[afteratsign] == 'x') break;
cout << "check to right of the at sign" << endl;
bool Dot = false;
if (validation(lineFromFile[afteratsign]) == false) break;
if (lineFromFile[afteratsign] == '.') Dot = true;
//fout << lineFromFile << ";" << endl;
}
// if (lineFromFile[beforeatsign] == 'x' && lineFromFile[afteratsign] == 'x') break;
if ((beforeatsign != 'x' && afteratsign != 'x') == true)break;
{
fout << lineFromFile << ";" << endl;
}
}
fin.close();
return 0 ;
}
on line 85 i didnt do that part right i need help on correcting it so that it checks if the email is valid or not. If it is valid it fouts it if its not it skips that email and goes on to the next.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
usingnamespace std;
bool validation (char c)
{
bool result = false;
if ( (c >='A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <='9') || c =='.'||c =='-' || c =='+')
{ result = true; }
return result;
}
int main () {
//bool ValidEmailCharacters;
string lineFromFile;
int locationOfAtSign = -1;
int beforeatsign;
int afteratsign;
string InputfileName;
string OutputFileName;
string defaultInputFile = "fileContainingEmails.txt";
string defaultOutputFile = "copyPasteMyEmail.txt";
ifstream fin;
ofstream fout;
cout << "Enter your Input file name (ENTER for Default): " ;
getline (cin, InputfileName);
if (InputfileName.length() < 2) {
InputfileName = defaultInputFile;
}
fin.open (InputfileName);
cout << "Enter your Output file name (ENTER for Default): " ;
getline (cin, OutputFileName);
if (OutputFileName.length() < 2) {
OutputFileName = defaultOutputFile;
}
fout.open (OutputFileName);
// Read a line from the input file
while (!fin.eof()) //reads until end of file
{
//
fin >> lineFromFile;
if (!fin.good()) break;
cout << lineFromFile << "////////////////////////////////////////////////////////////////////////// "<< endl;
// process the line
for (int i = 0; i < lineFromFile.length(); i++)
{
if (lineFromFile[i] == '@')
{
locationOfAtSign = i;
cout << "Test1-Found at sign" << endl;
}
}
//checking at left of at sign
for(beforeatsign = locationOfAtSign-1; beforeatsign >= 0; beforeatsign--)
{
if (lineFromFile[beforeatsign] == 'x') break;
cout << "Test2- check to left of the at sign" << endl;
if (validation(lineFromFile[beforeatsign]) == false) break;
}
cout << "validating" << endl;
// checking to the right of the at sign
for (afteratsign = locationOfAtSign+1; afteratsign < lineFromFile.length(); afteratsign++)
{
if (lineFromFile[afteratsign] == 'x') break;
cout << "check to right of the at sign" << endl;
bool Dot = false;
if (validation(lineFromFile[afteratsign]) == false) break;
if (lineFromFile[afteratsign] == '.') Dot = true;
//fout << lineFromFile << ";" << endl;
}
// if (lineFromFile[beforeatsign] == 'x' && lineFromFile[afteratsign] == 'x') break;
if ((beforeatsign != 'x' && afteratsign != 'x') == true)
{
fout << lineFromFile << ";" << endl;
}
elsebreak;
}
fin.close();
return 0 ;
}