/* The following #ifdef includes the mat_create function; you may wish to delete it and link the two files separately. */ #ifdef __cplusplus #include "lst13-2.cpp" /* or maybe "lst13-2.cxx" */ #else #include "lst13-2.c" #endif /*** Program to input two matrices and print their sum ***/ #include typedef struct { matrix m; int rows, cols; } s_mat; s_mat s_mat_create(int row, int column); void read_matrix(s_mat m, FILE *f); void sum_matrices(s_mat sum, s_mat a, s_mat b); main() { s_mat a, b, c; int rows, columns, i, j; FILE * inf; inf = fopen("lst13-3.dat", "r"); if (inf==NULL) { fprintf(stderr, "File open failure\n"); exit(EXIT_FAILURE); } fscanf(inf, "%d %d", &rows, &columns); a = s_mat_create(rows, columns); b = s_mat_create(rows, columns); c = s_mat_create(rows, columns); if (a.m==NULL || b.m==NULL || c.m==NULL) { fprintf(stderr, "Could not create matrices\n"); exit(EXIT_FAILURE); } read_matrix(b, inf); read_matrix(c, inf); fclose(inf); sum_matrices(a, b, c); /* Now print the sum matrix */ for (i=0; i