I trying to add two matrices together using a typedef struct, but i seems to get an error doing this. I asked my professor, but he couldnt help me. Is there anyone who might know why this problem is caused?

Thank you so much!

Code:

/* Structures */
typedef struct matrix {
int rows;
int cols;
float **mat;
} Matrix;
Matrix matrix_add(Matrix a, Matrix b){
Matrix m;
int i, j;
for (i=0; i<a.rows; i++) {
for (j=0; j<a.cols; j++) {
m.mat[i][j] = (a.mat[i][j]+b.mat[i][j]);
}
}
m.rows = a.rows;
m.cols = a.cols;
return m;
}

In matrix_add() function you are trying to use an uninitialized pointer m.mat. It has to be allocated memory before setting the array elements in those loops. Move the two lines m.rows = and m.cols = up above the two loops then allocate memory for m.mat.

In matrix_add() function you are trying to use an uninitialized pointer m.mat. It has to be allocated memory before setting the array elements in those loops. Move the two lines m.rows = and m.cols = up above the two loops then allocate memory for m.mat.

Thats was absolutely fantastic. I allocated memory by using:

/* Allocating mem for m.mat */
mat_temp = (float**) malloc(a.rows * sizeof(float*));
for (i = 0; i < a.rows; i++){
mat_temp[i] = (float*) malloc(a.cols * sizeof(float));
}
m.rows = a.rows;
m.cols = m.cols;
m.mat = mat_temp;

and then everything worked!

Thank you so much for you help. I can finally relax a bit now.

Greetings,
I have been trying to figure this out for hours with no avail. Basically I need to print out user input as Initial value, ASCII(char), ASCII(int), and Hex. I ...

Your program should read the input files by using Unix shell redirection (e.g. a.out<lab1.dat) to read the input from
stdin (C). By using redirection, it is unnecessary to open ...