need help asap!

So im working on a email parser that asks user to enter the file to be input and check the whole txt line by line for email addresses and only output email address to another file this is what i have so far
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
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct Email
{
  char s;
  char e;
  char c;
  char hasDot;
  string fileInput;
  string fileOutput;
};

bool checker(string aEmail)
{
  for(int i = 0; i < aEmail.size(); i++) 
  {
    if(aEmail.at(i) = '@') return true;
  }

return false;
}

int main()
{   
    string fileInput;
    ifstream fin;
    cout << "What file would you like to input to? [default: fileContainingEmails.txt]:  ";
    getline (cin, fileInput);
    fin.open(fileInput.c_str());
   
    if (fileInput == " ") 
      fileInput = "fileContainingEmails.txt";
      fin.open("fileContainingEmails.txt");
      fin.clear();
   
    
    const int MAX_EMAILS = 1000;
    int nEmails = 0;
    Email email[MAX_EMAILS];

while(!fin.eof())
{

string aEmail;
getline(fin,aEmail);


if(aEmail.find("@")!=string::npos)
// true if an @ sign is found.
{
if(aEmail.find(",")!=string::npos)
// true if a comma has been found.
{
if(aEmail.find(".")!=string::npos)
{
if(aEmail.find("+")!=string::npos)
{
if(aEmail.find("-")!=string::npos)
{
if(aEmail.find("_")!=string::npos)
{


}

{
cout<< aEmail<<" saved\n";
ofstream address;
address.open("copyPaste.txt",ios::app );
address << aEmail << endl;
address.close();
aEmail.clear();
}

}
}}}}

}
// close both files.















return 0;

}
Just checking for a '@' sign won't be enough to determine if something is an email will it?
Mmm... Perl...
1
2
3
4
5
6
7
8
9
10
11
my $vec = '[a-zA-Z0-9!#$%&\'*+\-/=?\^_`{|}~]'; #valid email charecters
my $uname = "$vec+(\\.$vec+)*"; #username
my $vdc = '[a-zA-Z0-9-]'; #valid domain characters
my $ipd = '([01]?\d{1,2}|2[0-4]\d|25[0-5])'; #ip digit
my $ip = "\\[$ipd\\.$ipd\\.$ipd\\.$ipd\\]";

while(<>) {
	while( s/((".+"|$uname)@($vdc+\.\w+|$ip))// ) {
		print "$1\n";
	}
}

http://en.wikipedia.org/wiki/E-mail_address#Syntax
Last edited on
Topic archived. No new replies allowed.