assistance with final assignment

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 maybe@yahoo@this@.com 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#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;
}
Last edited on
You can use string::find ( http://www.cplusplus.com/reference/string/string/find/ ) or std::find ( http://www.cplusplus.com/reference/algorithm/find/ ) to check whether StuffFromFile contains a '@' and a '.'
If you store the e-mail addresses in a container would be easy enough printing the results
Topic archived. No new replies allowed.