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;
}

You can use some string tokenizer class.

lol that wont help lol

I think that you probably want to use a vector. If you just print out the e-mail address right away and forget about it, you'll never be able to check for duplicates. So, each time you "find" an e-mail address see if it already exists in the vector. If not add it to the vector, if it does, then do not add it to the vector. When you are finished with the file, close it and print out the vector (which contains your e-mail addresses) to the console. The nice thing about vectors is that you can resize it each time you need to add another e-mail address--this way you don't have to try to guess what size you should make it.

For more information on vectors, see: http://www.mochima.com/tutorials/vectors.html

In order to compare e-mail addresses to see if they are the "same", you may need to use something like "toupper" or "tolower". I found this post on how to convert a string to all lower case: http://www.daniweb.com/forums/thread57296.html . Once both strings are all lower (or upper) case you can compare them. You may want to use a temporary variable for comparison but store the e-mail address how it originally existed in the file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.