!注:我有两个变量具有相同的名称......非常感谢斯特凡Birladeanu和亨里克的注意到,*访问冲突写入位置...错误在哪里? (图维奇)
最近我开始写代码,可以帮助我输入布尔值函数给Veitch(卡诺)4个变量的图表。该代码应写元件,以矩阵尺寸4×4,但是与这些索引:
- 元件 - 索引3,3
- 元件 - 索引2,3
- 元件 - 索引3,2
- 元件 - 指数2,2-
- 元件 - 索引0,3
- 元件 - 索引1,3
- 元件 - 索引0,2
- 元件 - IND离1,2-
- 元件 - 索引3,0
- 元件 - 索引2,0
- 元件 - 索引3,1
- 元件 - 索引2,1
- 元件 - 索引0,0
- 元件 - 索引1,0
- 元件 - 索引0,1
元件 - 索引1,1 这是代码的main():
void main() { int n; n=4; int **VeitchDiagram; //allocate memory for Veitch diagram VeitchDiagram = new int *[n]; for(int i=0; i<n; i++) VeitchDiagram[i]=new int [n]; //enter the elements for(int i=0; i<n; i++) { int j, k; if(i%2==1) { k=0; if(i<2) j=4; else j=-1; for(int k=0; k<2; k++) { if(i<2) j--; else j++; cin >> VeitchDiagram[k][j]; //this part writes the input to elements with index (at least it should do that): k++; //0,3 1,3 0,2 1,2 if i%2==1 and i<2 cin >> VeitchDiagram[k][j]; //0,0 1,0 0,1 1,1 if i%2==1 and i>=2 k--; } } else { k=3; if(i<2) j=4; else j=-1; for(int k=0; k<2; k++) { if(i<2) j--; else j++; cin >> VeitchDiagram[k][j]; //this part writes the input to elements with index (at least it should do that): k--; //3,3 2,3 3,2 2,2 if i%2==0 and i<2 cin >> VeitchDiagram[k][j]; //3,0 2,0 3,1 2,1 if i%2==0 and i>=2 k++; } } } //free memory allocated for VeitchDiagram for(int i=0; i<n; i++) delete [] VeitchDiagram[i]; delete [] VeitchDiagram; }
你是否已经通过调试器完成了它? – 2012-03-23 14:12:02
是...多次。它让我输入前两个元素,然后给我访问冲突。 – zkristic 2012-03-23 14:20:58