So as stated in the title I have a program to multiplies to matrices read from a file, but when I run it it simply crashes. I am required to have two functions to perform the multiplication and one to print the result while using pointers with no return values. Any help is appreciated.
#include<stdio.h>
#include<stdlib.h>
void mat_mult(int ** arr1, int rows1, int cols1, int ** arr2,
int rows2, int rcols2, int ** arr3);
void mat_out(int ** arr, int rows, int cols);
int main(void){
int **mat1, **mat2, **res, rows1, cols1, rows2, cols2, i, j;
FILE* f;
f = fopen("Matrices.txt", "r");
fscanf(f, "%d", &rows1);
fscanf(f, "%d", &cols1);
mat1 = (int**) malloc(rows1*sizeof(int*));
for(i = 0;i < rows1;i++){
mat1[i] = (int*)malloc(cols1*sizeof(int));
}
for(i = 0;i < rows1;i++){
for(j = 0;j < cols1;j++){
fscanf(f, "%d", &mat1[i][j]);
}
}
fscanf(f, "%d", &rows2);
fscanf(f, "%d", &cols2);
mat2 = (int**) malloc(rows2*sizeof(int*));
for(i = 0;i < rows2;i++){
mat2[i] = (int*)malloc(cols2*sizeof(int));
}
for(i = 0;i < rows2;i++){
for(j = 0;j < cols2;j++){
fscanf(f, "%d", &mat2[i][j]);
}
}
res = (int**)calloc(rows1,sizeof(int*));
for(i = 0;i < rows1;i++){
res[i] = (int*)calloc(cols2,sizeof(int));
}
/*mat_mult(mat1, rows1, cols1, mat2, rows2, cols2, res);
mat_out(res, rows1, cols2);*/
}
void mat_mult(int ** mat1, int rows1, int cols1, int ** mat2,
int rows2, int cols2, int ** res){
int i, j, k;
for(i = 0;i < rows1;i++){
for(j = 0;j < cols2;j++){
res[i][j] = 0;
for(k = 0;k < cols1;k++){
res[i][j] += mat1[i][k] * mat2[k][j];
}
}
}
}
void mat_out(int ** res, int rows, int cols){
int i, j;
for(i = 0;i < rows;i++){
for(j = 0;j < cols;j++){
printf("%d ",res[i][j]);
}
printf("\n");
}
}