[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

ifstream get parts of a formatted textfile

Asked by allmer in C++ Programming Language

Tags: get, ifstream

I am trying to extract to parts of unknown size from a database (textfile).
It is composed as follows
>Title\n                      //The '>' preceedes a section of the database and \n terminates this header
                                //That line thus contains the header or title for the following section
AACCCTAGCTAGCATCAGCACGACG\n
ACGACTAGCACTNACGGCGACCTCG\n
ACACGAGCTGCGCCATAGCAGCAGG\n
                               //Each line is terminated after some charackters with a linefeed '\n'
                               //Can be between some and some hundred thousands chaarackters.
                               //Only ACGNT however
>Next section\n
....
>Third section\n
...
>and so on for 100 MB\n
I would like to extract the header to a variable called scaffold
and the corresponding section of the database to a variable called code.
Boh are char*.
I use the following approach, but it only works for the first section thereafter it creates wierd
resutlts.
bool CDna2Protein::GetNextPart(const char * _filePath)
{
      if(!databasein.is_open())                         //Declared as class variable so I do not have
                                                                            //to keep opening and closing a file.
                                                                            //ifstream databasein;
            databasein.open(_filePath,ios_base::in);
      char          ch,
            test = '>';
      int pos = 0;
      char *line = new char[256];
      //Read in header for this part of the database
      databasein.getline(line,256,'\n');
      scaffold = new char[256];
      sprintf(scaffold,"%s",line);
      delete line;
      //Now get the current position in the file
      int before = databasein.tellg();
      before--; //Does seem to give the next position so account for that
      int after = 0;
      while(databasein.get(ch)) {
            if(ch == test) {    //test = '>';
                  databasein.putback(ch);
                           //I would like the next read starting with the charackter I just putback.
                  after = databasein.tellg();
                  after--;    //see above
                  break;
            }
      }
      int len = after-before;
                //Knowing the size of the database section create a buffer to hold it
      code = new char[len+1];
      databasein.seekg(before);
      databasein.get(code,len,test);   //test='>';
      databasein.seekg(after);
                //should hopefully end up at desired position within file
      code[len]='\0';

                //do some output for testing
      len = int(strlen(code));
      char *temp = new char[10];
      sprintf(temp,"%d",len);
      CString str = "Laenge von "+CString(scaffold)+": "+CString(temp);
      delete temp;
      StringToFile("c:\\gpfc++\\len.log",str);
      trim();
                //Need to figure out how to test for termination.
      return(true);
}
Besides the problem of getting wrong parts of the database posing for scaffold,
I also need to return false on reaching feof.
Thank you for any suggestions
Jens
[+][-]04/05/04 11:19 AM, ID: 10759727Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/05/04 12:41 PM, ID: 10760420Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/05/04 07:08 PM, ID: 10762547Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/06/04 12:57 AM, ID: 10763786Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/06/04 05:33 AM, ID: 10765182Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/06/04 02:11 PM, ID: 10769804Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/07/04 10:16 AM, ID: 10776634Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/07/04 11:12 AM, ID: 10777055Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/08/04 05:41 AM, ID: 10782883Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/08/04 01:03 PM, ID: 10786710Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/08/04 01:34 PM, ID: 10786938Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/13/04 12:29 PM, ID: 10816638Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/13/04 01:28 PM, ID: 10817211Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: C++ Programming Language
Tags: get, ifstream
Sign Up Now!
Solution Provided By: khkremer
Participating Experts: 2
Solution Grade: A
 
[+][-]04/16/04 11:53 AM, ID: 10845124Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/16/04 03:29 PM, ID: 10846547Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89