我正在尝试使用终端将数据输入到由双指针表示的二维数组中。
int main() {
int M, N;
printf("Please enter the number of rows in the array:");
scanf("%d", &M);
printf("Please enter the number of columns in the array:");
scanf("%d", &N);
int **A = (int**)malloc(M * sizeof(int *));
for (int i = 0; i < M; i++)
A[i] = (int *)malloc(N * sizeof(int));
// Assigning and printing 2d array
printf("Please enter the elements in the array:");
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
scanf("%d", &A[i][j]); <------- break here
}
}
printf("The array you entered was:");
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++) {
printf("%d\t", A[i][j]);
}
printf("\n");
}
return 0;
}
代码已成功构建,但当我尝试运行它时,程序停止在指定位置:(
为什么? :(最佳答案
从插图来看,您似乎已在指示的位置设置了断点。 尝试清除断点并再次运行程序。
关于c - 如何将数据输入到C中双指针表示的二维数组中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60130498/