Email parser

So I am writing this program and need some help!! I need to prompt the user to enter the file name they wish to input from and if nothing is entered to input a default folder. then i need to search the list testing each line for a @ and a . that makes it a valid email address then output to a file of the users choice this is what i have so far but cant seem to figure out how to search single line
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

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

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 (nEmails < MAX_EMAILS)
    {
      if (!fin.good()) break;
 
      Email aEmail;
      getline (fin, aEmail.fileInput);
     
      if (nEmails < MAX_EMAILS)
         email[nEmails++] = aEmail;

      else 
        cout << "No valid email addresses in file" << endl;
    }
    fin.close();

    bool validEmailCharacter(char c);
    {
      bool result = false;
      Email aEmail;
      ifstream fin;
      getline (fin, aEmail.fileInput);
      
     

    }

return 0;

}
You can use the string functions like find() or find_first_of(). They result the found position or string::npos if not found. Like
1
2
if(aEmail.find("@") == string::npos)
  cout << "Invalid email" << endl;


See http://www.cplusplus.com/reference/string/string/
Topic archived. No new replies allowed.