C++ search a text file

Discussion in 'Programming' started by sgrewal1, Apr 27, 2010.

  1. #1
    Hi guys....hope u doing well.

    I have programming assignment...
    I have 5 text file given...which have the format of the e-mail

    example..||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
    Received: (qmail 27680 invoked from network); 12 Jan 2003 15:21:26 -0000
    Received: from dev211.mailshell.com (HELO mailshell.com) (71.129.195.163)
    by dev50.mailshell.com with SMTP; 12 Jan 2003 15:21:26 -0000
    Received: (qmail 1953 invoked by uid 99); 12 Jan 2003 15:21:25 -0000
    Received: (qmail 24580 invoked from network); 12 Jan 2003 15:21:24 -0000
    Received: from unknown (HELO mta104.cheetahmail.com) (216.15.189.38)
    by www.mailshell.com with SMTP; 12 Jan 2003 15:21:24 -0000
    Date: Sun, 12 Jan 2003 15:21:47 -0000
    Message-ID: <amhe2xza9aqaf1bpagqeqbu4syp68c.155373475.987@mta104.circuitcity.chtah.com>
    From: "circuitcity.com" <circuitcity@circuitcity.chtah.com>
    To: "Mailshell User" <nospam@mailshell.com>
    Subject: Act Fast - Great Deals on the Hottest Electronics
    MIME-Version: 1.0
    Reply-To: "circuitcity.com" <support-amhe2xza9aqaf1bpagqeqbu4syp68c@circuitcity.chtah.com>
    Content-type: multipart/alternative; boundary="=amhe2xza9aqaf1bpagqeqbu4syp68c"


    --=amhe2xza9aqaf1bpagqeqbu4syp68c
    Content-Type: text/plain; charset="iso-8859-1"
    Content-transfer-encoding: 8bit



    --> Click here and get ready to save!
    http://circuitcity.chtah.com/a/tA$IXThAImq$2ALoYduAJQs$j.AJQRO-QA/free1


    **********************************************************
    Need to Unsubscribe?
    **********************************************************

    Please send an e-mail to remove-0amhe2xza9aqaf1bpagqeqbu4syp68c@circuitcity.chtah.com.



    Please send an e-mail to ccity_customer_support@circuitcity.com.

    --=amhe2xza9aqaf1bpagqeqbu4syp68c
    Content-Type: text/html; charset="iso-8859-1"
    Content-Transfer-Encoding: quoted-printable
    |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

    i need to extract the ip address and the domain name from this file...using c++

    I am a beginner....and i have tried to put the content of the file into a string...and that worked...but i don't know hw to go further....
    IF YOU HAVE ANY OTHER IDEA OF DOING THIS PLS TELL ME>>>
    here's my code:

    void search(string searchipDomain);
    int main() {
    string line;
    ifstream myReadFile ("file1.txt",std::ios::in);
    if(!myReadFile){
    cerr<<"File could not be opened"<<endl;
    exit(1);
    }
    else if (myReadFile.is_open()) {
    while(!myReadFile.eof()){
    string output;
    myReadFile>>output;
    search(output);
    }
    }
    myReadFile.close();
    return 0;
    }

    void search(string searchipDomain){
    cout<<searchipDomain;

    }
     
    sgrewal1, Apr 27, 2010 IP
  2. n3r0x

    n3r0x Well-Known Member

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    120
    #2
    Split on space making each string a word and check if it´s a IP "(*.*.*.*)" (I would use C style coding for this, sscanf) then use substr to remove the parentheses.
     
    n3r0x, Apr 28, 2010 IP