help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

email parser


From: Josh Henry
Subject: email parser
Date: Wed, 28 Mar 2012 18:29:51 -0000
User-agent: G2/1.0

cant figure out how to search line by line using most likely a bool
search loop for a valid email in a text file and only output the valid
email addresses to another file?? need help asap

[code]
#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;

}
[/code]


reply via email to

[Prev in Thread] Current Thread [Next in Thread]