Hi All,
Below is a piece code which im using to store some values from the array tempflow to flow.
I have an array of bytes whose size is unknown and to which i will have to reallocate each time.
However, when im compiling the program, my array flow is storing only one element.
Can anyone help me by suggesting something and pinpointing to me as to where the mistake might be?
Thanks,
int maxi=4;
unsigned char* flow = new unsigned char[maxi];
unsigned char* tempflow;
int _tmain(int argc, _TCHAR* argv[])
{
int count =0;
int value =0;
while(aa<flow_length)
{
count = tempflow[aa]; //Number of times of occurence
value = tempflow[aa+1]; //Value to be repeated
for(int j=0;j<count;j++)
{
flow[n]=value;
n=n+1;
if (n >= maxi)
{
maxi = maxi * 2; // double the previous size
unsigned char* temp = new unsigned char[maxi]; for (int i=0; i<n; i++)
{
temp[i] = flow[i]; // copy values to new array.
}
delete [] flow; // free old array memory.
flow = temp; // now a points to new array.
}
}
aa = aa+2;
}