c++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • factfinder
    New Member
    • Apr 2008
    • 3

    c++

    i have a text file like this
    <start>user data<end><start >userdata<start >userdata<end>< start>userdata

    i have to start reading from <start> and if i find corresponding <end >,then i have to delete that line from file i.e.from <start> to <end> including strings <start> and <end>.If for a given <start>, i dont find <end> then i have to keep that line in file .Here, user data can be any thing like int,char,string whatever.

    These are some details
    platform:redhat linux
    compiler:g++
    language:c++

    regards
    factfinder
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Originally posted by factfinder
    i have a text file like this
    <start>user data<end><start >userdata<start >userdata<end>< start>userdata

    i have to start reading from <start> and if i find corresponding <end >,then i have to delete that line from file i.e.from <start> to <end> including strings <start> and <end>.If for a given <start>, i dont find <end> then i have to keep that line in file .Here, user data can be any thing like int,char,string whatever.

    These are some details
    platform:redhat linux
    compiler:g++
    language:c++

    regards
    factfinder

    R u trying to write a XML validator or a html validator?

    Raghu

    Comment

    • questionit
      Contributor
      • Feb 2007
      • 553

      #3
      Originally posted by factfinder
      i have a text file like this
      <start>user data<end><start >userdata<start >userdata<end>< start>userdata

      i have to start reading from <start> and if i find corresponding <end >,then i have to delete that line from file i.e.from <start> to <end> including strings <start> and <end>.If for a given <start>, i dont find <end> then i have to keep that line in file .Here, user data can be any thing like int,char,string whatever.

      These are some details
      platform:redhat linux
      compiler:g++
      language:c++

      regards
      factfinder
      Hi

      Welcome to Bytes!

      Please post your work you have done so far and the experts here will be more than happy to assist you with your specific problem/query.

      Regards
      Qi

      Comment

      • factfinder
        New Member
        • Apr 2008
        • 3

        #4
        Originally posted by gpraghuram
        R u trying to write a XML validator or a html validator?

        Raghu
        Thanku for considering request.

        This is not Xml/html validator.i am creating a logfile and a function that do some cleaning job (space efficency).Thes e(<start>) are simple string inserted in file to recognise a start of user record.Actually , i have to start reading from <start> and if i find corresponding <end> ,it means that record(userdata ) is complete and i have to delete line.In case i do not find <end> coresponding to <start> i have to keep that line.please help me to write a function that could do this.

        regards
        factfinder .

        Comment

        • sicarie
          Recognized Expert Specialist
          • Nov 2006
          • 4677

          #5
          The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

          Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

          Then when you are ready post a new question in this thread.

          MODERATOR

          Comment

          • factfinder
            New Member
            • Apr 2008
            • 3

            #6
            Originally posted by questionit
            Hi

            Welcome to Bytes!

            Please post your work you have done so far and the experts here will be more than happy to assist you with your specific problem/query.

            Regards
            Qi
            I have the text file (in1.text)

            <<<start>20>>ev erything going fine or not<start>i do not know but I am trying<end><sta rt>Trying is but we can do<startabcdefg hijklmnopqrstuv wxyz<end>
            <<<start>20>>Tr ying to do things<end><<<s tart>20>>well try try and try again<end>


            I have to extract tag <<<start>20>> from file.My code is


            [code=cpp]
            std::ifstream fin;
            fin.open("in1.t xt");
            static int pos;
            int array[10];
            if (fin) {
            std::stringstre am ss;
            ss << fin.rdbuf();
            std::string contents = ss.str();


            for(int i =0,search;(sear ch= contents.find(" <<<start>", i))!= string::npos;i= search + 1)

            {

            start[search] = "<<<start>" ;
            array[pos]=search;
            pos++;

            }//end for

            for(int itr=0;itr<=pos; itr++)
            {
            int number=array[itr];
            string substring=conte nts.substr(numb er,number+13);
            cout<<substring <<"\n";
            number=0;
            [/code]
            The code is giving output

            [replyfast@local host NEW]$ ./a.out
            <<<start>20>>
            <<<start>20>> i am all right ,just trying to do things<end><<<s tart>20>>well try try and try again<end>

            <<<start>20>>we ll try try and try again<end>

            Aborted



            The first output is ok,but subsequent output gives some additional lines.How to rectify code so that it gives only <<<start>20>>
            I working on redhat linux(g++ compiler)




            Regards
            replyfast
            Last edited by sicarie; May 2 '08, 02:07 PM. Reason: Code tags, full code

            Comment

            • sicarie
              Recognized Expert Specialist
              • Nov 2006
              • 4677

              #7
              factfinder-

              I have already asked you to read the Posting Guidelines, so your lack of code tags and double-posting of the same question is unacceptable. Please read through the links I posted above and follow them in the future or we will have to take action against your account.

              Thanks,

              sicarie

              Comment

              Working...