so I am trying to input text from a file to make a square matrix multiplication algorithm. My first function actually fills all the m[I][J] entries from the file. The text file is formatted like this:
3 //an int that determines the size of the square matrix so in this case 3X3
1 2 3 //the entries for the matrix, N lines of numbers with N numbers in each line
4 5 6
7 8 9
2 // the exponent to multiply the matrix
So the SEGV error is caused by line 15 which is fscanf(file, "%d", &m1[i][j]);
here is the entire method in question
void matrixFill(int** m1, int** m2,int n){
int i,j;
for(i=0; i<n;i++){
for(j=0;j<n;j++){
fscanf(file, "%d", &m1[i][j]);
m2[i][j] = m1[i][j];
}
}
}
int main (int argc, char** argv){
file = fopen(argv[1], "r");
int size;
fscanf(file, "%d", &size);
int **matrixOne = (int **)malloc(size * sizeof(int *));
int **matrixTwo = (int **)malloc(size * sizeof(int *));
int **result = (int **)malloc(size * sizeof(int *));
matrixFill(matrixOne,matrixTwo,size);
return 0;
}
Am I even scanning the file right? Keep in mind the first number (the dimension) is already scanned so I think it will start scanning from the 1.