I am currently trying to initialize a 2d array with values but keep encountering a segmentation fault...I noticed it always occurred when I added the fscanf line of code...but I don't understand what's wrong with it since from my understanding it should work...this is a code snippet:
FILE * fp;
int count, i,j;
int **arr;
arr = (int**)malloc(sizeof(int*)*9);
for(i = 0; i < 9; i++){
arr[i] = (int*)malloc(sizeof(int)*9);
}
fp = fopen("input.txt", "r");
for(i = 0; i < 9; i++){
for(j = 0; j < 9; j++){
fscanf(fp, "%d", &arr[i][j]);
}
}