I am trying to write a program that takes email addresses out of a text file (for easy copy paste) but when it finds one and prints it to the console it skips to the next line. So if there are two email addresses in one line it will only print the first one. I just threw in a cout in order to check it, I still have a few things to do but I've gotten stuck on this part, so there is missing pieces. It is for a class so if anyone has any input where I need to review it would be much appreciated. Attached is one of the files I am using to test.
Thank you.
while (true)
{
if (!fin.good()) break;
string lineFromFile;
getline(fin, lineFromFile);
for (int i = 0; i < lineFromFile.length(); i++) // for each char in the string...
if (lineFromFile[i] == '@')
{ // front and back traverse
s = i;
while (true)
{
s--;
if (s < 0) break;
if (isValidEmailCharacter(lineFromFile[s]) == false) break;
}
s++;
int e = i;
bool hasDot = false;
while (true)
{
e++;
if (e == lineFromFile.length()) break;
if (isValidEmailCharacter(lineFromFile[e]) == false) break;
if (lineFromFile[e] == '.') hasDot = true;
}
if ( s < i && e > i && hasDot == true)
{
anEmail = lineFromFile.substr(s, e-s);
cout << anEmail << " ";
// set aName's value
if (nEmails < MAX_EMAILS)
email[nEmails++] = anEmail;
break;
}
} // end front and back traverse
} // while
fin.close();