So I find the number of lines in an unknown matrix and then want to use this number to scan through the matrix the correct number of times and display the matrix at the end. I need to find the dimension as i want to go on to find the determinant but this is my code so far.
Anyway the problem is that the "dim" integer doesn't seem to transfer as it prints out a bunch of crazy numbers
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char* argv[])
{
FILE *input;
int i, j, temp, dim;
float fullmatrix[dim][dim];
const char inp_fn[]="matrix.dat";
/*Open File*/
input = fopen(inp_fn, "r");
dim = 0;
while (EOF != (temp = fgetc(input)))
{
if (temp=='\n')
{
++dim;
}
}
if( (input != (FILE*) NULL) )
{
for(i=0; i<=dim; i++)
{
for(j=0; j<=dim; j++)
{
fscanf(input, "%f", &fullmatrix[i][j]);
printf("%f ", fullmatrix[i][j]);
}
printf("\n");
}
fclose(input);
}
else
{
printf("Could not open file!\n");
}
return(0);
}
I'm pretty new to this so i'm probably being stupid.