C++ don't know why content is changed
<p>The code is from my friend. Please have a look at it and give us some suggestions.</p>

<pre><code>in VoltageForDisplayAndAnalyze.h file

private:

string *    grpVolFileName[ MAX_NUM_OF_GROUP ]; //for voltage files
fstream *   aStream_grpVolt[ MAX_NUM_OF_GROUP ];

in VoltageForDisplayAndAnalyze.CPP file

void VoltageForDisplayAndAnalyze::MakeFileNameForGroupCell( int xgrpIndex )
{
   int numOfFiles = (EEnd - EBegin + 1) / 255;
   grpVolFileName[ xgrpIndex ] = new string[ numOfFiles ];      
   assert( grpVolFileName[ xgrpIndex ] != NULL );
   aStream_grpVolt[xgrpIndex] = new fstream[ numOfFiles ];  
   assert( aStream_grpVolt[ xgrpIndex ] != NULL );
   .....
   for( int fileIndex=0; fileIndex&lt;numOfFiles; fileIndex++ )
   {            
    char * tempbuf = new char[256];
    memcpy(tempbuf, mPath.c_str(), mPath.length() );
    tempbuf[mPath.length()] = '\0';
    char * numChar = new char[4];
    itoa(xgrpIndex, numChar, 3 );
    numChar[3] = '\0';   

    strcat(tempbuf, numChar );
    grpVolFileName[ xgrpIndex ][ fileIndex ].assign(tempbuf );

    }    
     ....
}
</code></pre>

<p>we print out in above method which assign values to grpVolFileName, the result looks good. These values are location of some files.  Then the following method is called to use above grpVolFileName array of string pointers. It is good for first 4 and then the print out show the directory cannot being print out correctly, some squares are print out and error happened. But it is not always at the 4th, sometime it happens at very begining.</p>

<pre><code>void VoltageForDisplayAndAnalyze::SaveDataForGrpCell( int grpIndex, int fileIndex, int xBegin, int xEnd     {

    int i = 0;
    char answer;

//save to hard disk
aStream_grpVolt[grpIndex][fileIndex].open(  grpVolFileName[grpIndex][fileIndex].c_str() , fstream::out | std::ofstream::app );
cout &lt;&lt; "open file: grpIndex= " &lt;&lt; grpIndex &lt;&lt;"  fileIndex= " &lt;&lt; fileIndex &lt;&lt; " :  " &lt;&lt; grpVolFileName[grpIndex][fileIndex] &lt;&lt; " to save." &lt;&lt; endl;
if( aStream_grpVolt[grpIndex][fileIndex].good() )
{   
   //.....  
}
else
{

    cout &lt;&lt; "Cannot open file: " &lt;&lt; grpVolFileName[grpIndex][fileIndex] &lt;&lt; endl;
   }

   //.......
}
</code></pre>

<p>print out from above method like those:</p>

<pre><code>...
open file: grpIndex= 2  fileIndex= 0 :  C:\Workspace\UncusJava\DataFiles\spc1\2 to save.
open file: grpIndex= 3  fileIndex= 0 :  C:\Workspace\UncusJava\DataFiles[][][][]4@ to save.
</code></pre>

<p>that means the grpVolFileName array has been changed in the process. It causes this if clause, <code>if( aStream_grpVolt[grpIndex][fileIndex].good() )</code>
, returns flase and error happen.</p>

<p>I searched entire solution (Visual Studio 2008), above two methods are only places use the grpVolFileName array of pointers. It is a single thread for this part.</p>

<p>Any comments?</p>
