【发布时间】:2019-05-05 17:04:00
【问题描述】:
我有两个 4x4 多维数组,行和列分别标记为A、B、C 和D。当用户输入坐标时,选择的 known_location_info 的值被更改为 bomb_location_info 的值。例如,如果输入了AA,则known_location_info 上的[1][1] 值将更改为bomb_location_info 上[1][1] 的值。目前,无论输入什么坐标,我都只会改变第一个元素。我的循环中有什么不正确的地方?
char inputRow;
char inputColumn;
char letterA = 'A';
void display(int known_location_info[][DIM], int size) {
printf(" A B C D\n");
for (int row = 0; row < DIM; row++) {
printf("%c", letterA);
letterA++;
for (int column = 0; column < DIM; column++) {
printf("%d ", known_location_info[row][column]);
}
printf("\n");
}
printf("Please select a row and column: ");
scanf("%c, %c", &inputRow, &inputColumn);
}
void update_known_info(int row, int col, int bomb_location_info[][DIM],
int known_location_info[][DIM]) {
for (inputRow = letterA; inputRow < DIM; inputRow++) {
for (inputColumn = letterA; inputColumn < DIM; inputColumn++) {
row++;
col++;
}
}
known_location_info[row][col] = bomb_location_info[row][col];
}
【问题讨论】:
-
你检查过
inputRow和inputColumn的值吗?