Run-Time Check Failure #2 - Stack around the variable 'Lmk' was corrupted.

int main (int argc, char **argv)
{
// int i,m;
double v1[kmax],v2[kmax],Ng,Lk[kmax],Hmax,Lmk[N],FD;
//double Lk1 = 0.0;
double x1[N];
loadImage("../sierpinski10.pgm");
printf("Bnorm[40][2] = %f",Bnorm[40][2]); //test
// Lmk[0] = 0.0; Lk=0.0;
double sum = 0.0;
for(int i=0;i<N;i++){
sum = 0.0;
for(int j=0;j<N;j++){
sum+=Bnorm[i][j];
}
x1[i]=sum;
}
//for(m=1;m<=N;m++){
for(int k=0;k<kmax;k++)
{
Lk[k]=0.0;
for(int i=0;i<N;i++){
Lmk[i] =0.0;
Hmax = (N-i)/(double)k;
Ng = (N-1)/(Hmax*k);
for(i=0;i<=N;i++)
{
Lmk[i] = Lmk[i]+ abs(x1[i+1]-x1[i]*Ng);
}
Lk[k] = Lk[k] + Lmk[i]/(double)k;
}
Lk[k]=Lk[k]/(double)k;
}
for(int k=0;k<kmax;k++)
{
v1[k] = log((double)k);
v2[k] = log(Lk[k]);
}
FD =lreg(kmax,v1,v2);
fprintf(fout,"%f\n",FD);
return(0);
}

Note:Can somebody please help me to check this code;I am receiving error "Run-Time Check Failure #2 - Stack around the variable 'Lmk' was corrupted."
Your code does not compile.
Also, use code tags when posting
Yes I am sorry, I only copied the main code. And secondly there is an image on my desktop tha6t has to be loaded. kunleuc
1
2
3
4
5
6
7
for(int i=0;i<N;i++){
    Lmk[i] =0.0;
    Hmax = (N-i)/(double)k;
    Ng = (N-1)/(Hmax*k);
    for(i=0;i<=N;i++)
    {
        Lmk[i] = Lmk[i]+ abs(x1[i+1]-x1[i]*Ng);


Do you really want to reuse i in the inner for loop there? Lmk is defined as an array that may hold N objects. Clearly here, i may be equal to N which is outside the range of valid indices for Lmk (and coincidentally also outside the range of valid indices for x1.)
Topic archived. No new replies allowed.