I've been given a txt file with 5 lines. The first two lines are number values indicating the dimensions of a matrix, and the next 3 are the subsequent values in the matrix.
Ex:
3
4
0.0 1.0 2.0 3.0
10.1 11.1 12.1 13.1
200.2 210.2 220.2 230.2
So far, all I was trying to do was see if I could create a matrix by fscanf the first two lines and get the number of rows and columns like so:
/*Matrix reading*/
matrix_t mat_frd(char* fname){
int r,c;
r = 0;
c = 0;
matrix_t mfile;
FILE * matrix_file;
matrix_file = fopen(fname, "r");
rewind(matrix_file);
fscanf(matrix_file, "%d", r);
printf("%d",r);
printf("%d",c);
mfile = mat_new[r][c];
return mfile;
}
I was trying to just see if I could even print those two values if see if I got them, but I think I am scanning through the file wrong. The ultimate goal is to be able to create the matrix with the specifications in the file, and then use another method to print it, but I am still stuck here.
matrix_fileNULL?c, so it remains with a value of0.