email parser questions??

so i have been working on this program to prompt user for both input and output files with default file.txt if enter is hit so then after that i need to search the input text doc for any valid email addresses storying them and then outputing the output file of choice
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
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

bool isValidEmailCharacter(char c)
{
  bool result = false; 
  if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z' && c <= '9') || (c == '.')|| (c == '-')||
     (c == '+')|| (c == '_'))result = true;

  return result;
}

int main()
{
  const int MAX_EMAILS = 1000;
  int nEmails=0;
  string email[MAX_EMAILS];

  ifstream fin;
  string fileName;
  string dFileName ="fileContainingEmails.txt";
  cout << "What is the file called?";
  getline(cin,fileName);

  ofstream fout;
  string outFileName;
  string dOutFileName ="copyPasteMyEmails.txt";
  cout << "What file do you want to use for output?";
  getline(cin, outFileName);
  string lineFromFile;

  if (fileName.length()==0)
  {
    fileName = dFileName;
    outFileName = dOutFileName;
  }

  fin.open (fileName.c_str());
  fout.open(outFileName.c_str());
  int s;
  int e;
  getline(fin, lineFromFile);

  for (int i = 0; i < lineFromFile.length(); i++) // for each character in the string
  {

    if(lineFromFile[i]=='@')
    {

      for (s = i; s >= 0; s--)
      {
        if (!isValidEmailCharacter(lineFromFile[s])) break;
      }
      for (e = i; e < lineFromFile.length(); e++)
      {
        if (!isValidEmailCharacter(lineFromFile[e])) break;

  if (nEmails > MAX_EMAILS)
  email[nEmails++]= lineFromFile;
  cout << lineFromFile << "; " << endl;
  fout << lineFromFile << "; " << endl;
}

}

}
fout.close();
fin.close();

return 0;
}
Topic archived. No new replies allowed.