我在使用指针时遇到了一些麻烦。我试图填充这个 2D 矩阵,但我无法打印它们的值。你能看一下并给我一个提示吗?
#include <stdio.h>
#include <stdlib.h>
#define L1 3
#define C1 2
#define L2 4
#define C2 3
void write(int *p, int n_lin, int n_col){
int i,j;
for(i=0;i<n_lin;i++){
for(j=0;j<n_col;j++){
printf("%d",*p[i][j]); // <- Can't make it work :(
}
printf("\n");
}
}
void main(){
int *p=NULL;
int mat1[L1][C1] = {{1,2}, {3,4}, {5,6}};
int mat2[L2][C2] = {{1,2,3}, {4,5,6}, {7,8,9}, {10,11,12}};
printf("Matriz 1:\n");
write(*mat1, L1, C1);
printf("\nMatriz 2:\n");
write(*mat2, L2, C2);
system("pause");
}
谢谢。