Okay i have a problem again, it does read the file: but it does it in a weird order.
Matrix.dat contains:
Code:
1.001 -2.2000 3.1366
5.8111 9.0003 -1.1064
-3.3098 2.8243 4.5333
My program looks like
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
/*need to use an external function to computer det of a minor (2x2 matrix)*/
/*Need to read from a file named matrix.dat*/
/* Prototype your function here, also make sure you change all of these comments*/
float ReadFromFile(float fullmatrix[3][3], FILE *input);
float minordet(float minor[2][2]);
int main(int argc, char* argv[])
{
FILE *input;
int i, j;
float fullmatrix[3][3];
const char inp_fn[]="matrix.dat";
/* Open files */
input = fopen(inp_fn, "r");
/* Check the pointers to files are not NULL, also check matrix has correct number of elements */
if( (input != (FILE*) NULL) )
{
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
fullmatrix[i][j]=ReadFromFile(fullmatrix, input);
}
fscanf(input, "%f");
}
fclose(input);
printf("%f %f %f\n %f %f %f\n %f %f %f\n", fullmatrix[0][0], fullmatrix[0][1], fullmatrix[0][2], fullmatrix[1][0], fullmatrix[1][1], fullmatrix[1][2], fullmatrix[2][0], fullmatrix[2][1], fullmatrix[2][2]
);
return(0);
}
else
{
printf("*** Could not open input file, or there are not 9 elements in the matrix ***\n");
}
}
/*Write the external fucntion here, need a 2 dimensional array http://www.dfstermole.net/OAC/harray2.html*/
float minordet(float minor[2][2])
{
float minordet;
}
float ReadFromFile(float fullmatrix[3][3], FILE *input)
{
float element;
fscanf(input,"%f,", &element);
return (element);
}
and when it is run it shows
Code:
1.001 -2.2000 3.1366
9.0003 -1.1064 -3.309800
4.5333 4.5333 4.5333
Any idea what the problem is?