c++ - Loop - Access violation writing location 0xabababab -


when set loop iterate 10 times works, no matter how many iterations set brings error on 12 time. here code below.

does know why happens? or if there logic error in code missing out on. thanks

string* analyser::topfivebuyers() { //set size , add buyer names comparison. string *calcstring = new string[ssize]; int calctotal[ssize] = {int_min, int_min, int_min, int_min, int_min};  //checks transactions (int = 0; i<ntransactions; i++) {     //compares arrays     for(int j =0; j<ssize; j++)     {      if(calctotal[j] < calctotal[j+1])     {     int tvar = calctotal[j+1];     string tstr = calcstring[j+1];     int tvartwo = calctotal[j];     string tstrtwo = calcstring[j];      calctotal[j] = tvar;     calcstring[j] = tstr;     calctotal[j+1] = tvartwo;     calcstring[j+1] = tstrtwo;     }          if(tarray[i].buyername == calcstring[j])         {         calctotal[j] += tarray[i].numshares;         break;         }         else             {                 //checks if shares great current total replaces                 if(tarray[i].numshares > calctotal[j])                 {                     int tvar = calctotal[j];                     calctotal[j+1] = tvar;                     string tstr = calcstring[j];                     calcstring[j+1] = tstr;                     calctotal[j] = tarray[i].numshares;                     calcstring[j] = tarray[i].buyername;                     break;                 }             }     } } return calcstring; 

you accessing calcstring[j+1] , calctotal[j+1] , j equal ssize-1 on last loop run. going outside array bounds.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -