okay, i wouldnt be asking for help if i didnt need. im completely stuck and have no idea HOW to fix it. my teacher didnt really teach how to figure out these things, he basically left the last assignment as a "teach ourselves" moment.
anyway...whole point of the assignment is to open a TXT file and be able to read email addresses and print on console.
i am to test with 3 different kinds of TXT files...
1st file has:
blahblah@yahoo.com hello how are you yay@mail.com woopie blah blah checkitout@blah.com
2nd file has:
<html> this that <this> mailto: yay@kris.com <why> heyyy <morehtml> <href> code here and there mailto: wiki@jenga.com <yay>
3rd file has:
kristine@yahoo.com kRISTINE@yahoo.com hey why are you going this here kRiStINe@yahoo.com but blahlah cupcake makesthis [email]maybe@yahoo@this@.com[/email] heyy@blank.com
our OUTPUT should look like:
email@this.com; kristine@yahoo.com; blahblah@yahoo.com
confusing enough? lol
BASICALLY, he wants the emails to be printed to the console ONLY once, regardless of how it is spelled whether it was THiS or this. he wants only email addresses.
MY PROBLEM:
well, i got the 1st test to work.
im having HUGE issues on how to get the other 2 to work. how do i ignore other characters?! and just list the emails? (NO DUPlicates either)
its dumb that he never taught us how to properly do it, but im just relieved that i got THIS far in it somehow.
any pointers how i can progress with this?
my current code is below, if you guys have time to check it out. thank you. any suggestion or help would be absolutely appreciated and crucial to my progression. thank you.
PS: why my code looks the way it is because im following my teacher's specs. he likes clutter, not really, but were in an intro to c++ class. so its super basic how everything is set up. =P
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
// strings
string DefaultInput = "fileContainingEmails.txt";
string DefaultOutput = "copyPasteMyEmails.txt";
string FileNameInput;
string FileNameOutput;
// prompts for input?
ifstream fin;
cout << "Enter input file name [default: " << DefaultInput << "]: ";
getline(cin, FileNameInput);
if(FileNameInput.length() == 0)
FileNameInput = DefaultInput;
else
DefaultOutput = FileNameInput;
fin.open(FileNameInput.c_str());
if(!fin.good()) throw "I/O error";
// EOF loop
while(true)
{
if(!fin.good()) break;
string StuffFromFile;
string Line;
fin >> StuffFromFile;
for (int i = 0; i < StuffFromFile.length(); i++)
{
if (StuffFromFile[i] == '@')
cout << StuffFromFile << endl;
for (int i = 0; i < StuffFromFile.length(); i++)
{
bool hasDot = false;
int s;
int e;
if(StuffFromFile[i] == '@')
{
for (int s = 0; s < StuffFromFile.length(); s--)
{
if (StuffFromFile == "<") break;
}
for (int e = 0; e < StuffFromFile.length(); e++)
{
if (StuffFromFile == ".") hasDot = true;
if (StuffFromFile == ">") break;
}
if (hasDot) cout << StuffFromFile.substr(s,e) << endl;
}
}
}
}
fin.close();
fin.clear();
// prompts for output?
ofsmtream fout;
cout << "Enter output file name [default: " << DefaultOutput << "]: ";
getline(cin, FileNameOutput);
fout.open(FileNameOutput.c_str());
fout.close();
// print them both
cout << " " << endl;
cout << FileNameInput << endl;
cout << FileNameOutput << endl;
cin.get();
return 0;
}