变量在循环中发生改变
if(L.length<10)
L.length++;
return 0;}
else {
for(j=L.length;j>=mid+i;j--){
printf("%d_11\n",L.length);//检查
L.r[j+1]=L.r[j];}
printf("%d_12\n",L.length); //当length=9时,此处会发生改变,为-2;其他时候正常,比如length为1,2,3等
L.r[mid+i]=n;
if(L.length<10)
L.length++;
return 0;
}
}
else if(L.r[mid].money<n.money)
low=mid+1;
else
high=mid-1;
}
if(L.r[low].money>n.money){
for(j=L.length;j>=low;j--){
printf("%d_21\n",L.length);//检查
L.r[j+1]=L.r[j];
printf("%d_22\n",L.length);// 同样,当length=9时,此处会发生改变,为-2;其他时候正常,比如length为1,2,3等
}
L.r[low]=n;
if(L.length<10)
L.length++;
return 0;
}
else if(L.r[low].money<=n.money){
for(j=L.length;j>=low+1;j--){
printf("%d_31\n",L.length);//检查
L.r[j+1]=L.r[j];
printf("%d_32\n",L.length); }//同样,当length=9时,此处会发生改变,为-2;其他时候正常,比如length为1,2,3等
L.r[low+1]=n;
if(L.length<10)
L.length++;
return 0;
}
}
}
int main()
{
sqlist L;
im m;
int i;
L.length=0;
while(1){
system("cls");
for(i=L.length;i>=1;--i)
printf("%d\n",L.r[i].money);
printf("请输入你的金额:\n");
scanf("%d",&m.money);
compare(L,m);
system("pause");
}
return 0;
}
程序就是这样。
[解决办法]
[解决办法]
lz,感觉代码太长,没看,太累
不过问题的原因是:
在length=0~8时,处理覆盖了length=9时的空间,或者在length==0的时候,就扩大了一点范围,累加到9的时候,就完全覆盖了,具体是哪个语句,请lz自己找了。。。。
[解决办法]
To set a breakpoint when a variable changes value
From the Edit menu, click Breakpoints.
Click the Data tab of the Breakpoints dialog box.
In the Expression text box, type the name of the variable.
Click OK to set the breakpoint.