Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        8天前关闭。
                                                                                            
                
        
我正在尝试使用终端将数据输入到由双指针表示的2d数组中。

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;
}


代码已成功构建,但是当我尝试运行它时,程序在指定的位置停止:(

This is what it looks like in Xcode
This is the terminal

为什么? :(

最佳答案

从插图中,您似乎已在指示的位置设置了一个断点。
尝试清除断点,然后再次运行程序。

关于c - 如何在C中将数据输入到由双指针表示的2D数组中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60130498/

10-08 22:40