Well did you call it 3 times?
read( mat1, n, fp );
read( mat2, n, fp );
read( mat3, n, fp );
?
You're not returning n.
By the way, n should be a local variable. It's useless as a parameter.
ThenCode:void read(double a[N][N], FILE* inp) { int i,j,n; fscanf(inp,"%d", &n); for (i=0; i<n; i++) { for (j=0;j<n;j++) fscanf(inp, "%lf", &a[i][j]); } return n; }
n1 = read( mat1, fp );