I have to read the number of rows and columns of a matrix from a txt file also its elements. the first row is the number of rows and columns followed by its numbers. For example this is a matrix with 2 rows and 3 columns containing 123 456 and a matrix with 3 rows and 2 columns.
2 3
1 2 3
4 5 6.
3 2
1 2
3 4
5 6
What I have to do is to read two matrix from the same text file and multiply them. I'm encountering some unknown problem.

When I write my code to test whether the matrix is populated correctly. I only get the first matrix printed and then the program stopped. Output: 1 2 3
 4 5 6

Here's the part of the code. Thanks in advance. 

```
int main(){
int **mat1,**mat2,**result;
int row1,col1,row2,col2;
int i,j,k;
FILE *file;

char fname[100];

printf("enter file name\n");
scanf("%s", &fname);
file=fopen(fname, "r");

fscanf(file, "%d    %d", &row1,&col1);//row of first matrix

mat1=malloc(row1 * col1 * sizeof(int*));//create memory for first matrix
//reading data for first matrix
for(i=0; i<row1; i++)
{
    for(j=0; j<col1; j++)
    {
        fscanf(file, "%d", &mat1[i][j]);
    }
}
for(i=0; i<row1; i++)
{
    for(j=0; j<col1; j++)
    {
        printf("%d\t",mat1[i][j]);
    }
    printf("\n");
}
fscanf(file,"%d %d", &row2, &col2);//row of second matrix

mat2=malloc(row2 * col2 * sizeof(int*));//create memory for second matrix
//reading data for second matrix

for(i=0; i<row2; i++)
{
    for(j=0; j<col2; j++)
    {
        fscanf(file,"%d",&mat2[i][j]);
    }
}
for(i=0; i<row2; i++) //check mat2
{
    for(j=0; j<col2; j++)
    {
        printf("%d\t",mat2[i][j]);
    }
    printf("\n");

```

}