By the way the error says that "subscripted value is neither array nor pointer". Here is how I changed the code
Code:
#include <stdio.h>
/* Creates structure */
typedef struct {
int n;
double *entry; }
matrix;
/*Initializes matrix pointers, size, and the loop variables (i,j,k). Also initilizes character array. */
FILE *file;
char filename[]="";
int n,i,j,k;
matrix *a;
matrix *b;
matrix *c;
int main (void) {
printf("Please enter the input file: "); /* Asks user for the name of the file that holds their matrix info */
scanf("%s", &filename); /*Scans user's string and saves it in filename */
file = fopen(filename, "r"); /* Opens the file the user input */
if (file != NULL) { /*Checks if the file can be opened. */
}
else
{
printf("Error: File Not Found"); /* If file is not found, error message shows. */
}
fscanf(file,"%d", &n); /* Scans file for integer and stores this integer in n */
/* Allocates space for matrices (a, b, and result in c) */
a=(matrix *)malloc(sizeof(matrix));
b=(matrix *)malloc(sizeof(matrix));
c=(matrix *)malloc(sizeof(matrix));
a =(double *)malloc(sizeof(double)*n*n);
b =(double *)malloc(sizeof(double)*n*n);
c =(double *)malloc(sizeof(double)*n*n);
buildMatrix(n);
}
/*Places values into matrix a and b from text file */
void buildMatrix(n) {
printf("\nMatrix A includes: \n");
for (i=0;i<n;i++) {
fscanf(file,"%lf\t", a[i]+j);
}
printf("\nMatrix B includes: \n");
for (j=0;j<n;j++) {
fscanf(file,"%lf\t", b+j);
}
}
void matrixMultiply(n) {
for(i=0;i<n;i++) {
for(j=0;j<n;j++) {
float sum=0.0;
for(k=0;k<n;k++)
{
sum=sum+(a[i][k]*b[k][j]);
c[i][j]=sum;
}
printf ("%.2lf\t",c[i][j]);
}
}
}