Parsing columns into arrays, while discriminating whats in the rows
<p>I'm trying to parse a text file that is outputted like the example below, my example has limited entries but my actual one has over 15000 lines, so i can't read these in individually:</p>

<p>ID   IC   TIME</p>

<p>15:23:43.867 /g/mydata/dataoutputfile.txt identifier</p>

<p>0003 1233 abcd</p>

<p>0043 eb54 abf3</p>

<p>000f 0bb4 ac24</p>

<p>000a a325 ac75</p>

<p>0023 0043 ac91
15:23:44.000 /g/mydata/dataoutputfile.txt identifier</p>

<p>0003 1233 abcd</p>

<p>0043 eb54 abf3</p>

<p>000f 0bb4 ac24</p>

<p>000a a325 ac75</p>

<p>0023 0043 ac91</p>

<p>Is kind of the output I have. The time column resets every so often.</p>

<p>What I am doing now is making 2 additional columns in addition to the 3 i have in my example. The first column is the conversion of the ID column, into a translation into an understandable message. The second additional column will calculate the difference between each time code, except when the time code resets.</p>

<p>My logic is, is to read each column into an array so I can perform the necessary translations and operations.</p>

<p>I am focusing on getting the timecode differential first, as I think getting the translation will be a bit simpler.</p>

<p>The problem I'm having is getting the entries read into their matrices:</p>

<p>my code looks a bit like this:</p>

<pre><code>while(readOK &amp;&amp; getline(myfile,line))
{
stringstream ss(line);
string ident,IC,timehex,time,filelocation;
string junk1,junk2;
int ID[count];
int timecode[count2];
int idx=0;

if(line.find("ID") !=string::npos)
{
     readOK=ss&gt;&gt;ident&gt;&gt;IC&gt;&gt;timehex;
     myfile2&lt;&lt;ident&lt;&lt;"\t\t"&lt;&lt;IC&lt;&lt;"\t\t"&lt;&lt;timehex&lt;&lt;"\t\t"&lt;&lt;"ID Decoded"&lt;&lt;"\t\t"&lt;&lt;"DT"&lt;&lt;endl;
     myfile3&lt;&lt;"headers read"&lt;&lt;endl
}

else if(line.find("identifier") != string::npos)
{
     readOK=ss&gt;&gt;time&gt;&gt;filelocation;
     myfile3&lt;&lt;"time and location read";
     myfile2&lt;&lt;time&lt;&lt;"\t\t"&lt;&lt;filelocation&lt;&lt;endl;
}

else //this is for the hex code lines
{
     readOK=ss&gt;&gt;hex&gt;&gt;ID[idx]&gt;&gt;IC&gt;&gt;timecode[idx];

     if (readOK)
     {
          myfile2&lt;&lt;setw(4)&lt;&lt;setfill('0')&lt;&lt;hex&lt;&lt;ID[1000]&lt;&lt;"\t\t"&lt;&lt;IC&lt;&lt;"\t\t"&lt;&lt;timecode[1000]&lt;&lt;endl;
          myfile3&lt;&lt;"success reading info into arrays"&lt;&lt;endl;
     }

     else
     myfile3&lt;&lt;"error reading hex codes"&lt;&lt;endl;
}
idx++;
}
</code></pre>

<p>Although this code doesn't work correctly. I can't just read in every line quite the same because of the intervening time and file location entries that are inserted to help keep track of when I am looking at in my code.</p>

<p>My gut is telling me that I'm calling the matrix entries too early and they haven't been filled yet, because if I cout number 1000, I get a 0 (i have well over 15000 lines in my input file and I have the boundaries of my arrays set dynamically in another part of my program). </p>

<p>I can't seem to figure out how to get the entries assigned correctly as I am having some inheritance issues with the count variable resetting to 0 every time through the loop.</p>
