I have a text file with some numbers but in the form of a matrix and I want to store them as a vector. Here is what is in the file:
3 (since its always square, I only need one number for the rows and columns)
1 2 3
0 1 2
1 4 5
and my code is:
Code:
main()
{int i;
float *XAtemp, row_col;
FILE *isa;
isa=fopen("file.c","r");
fscanf(isa,"%f",&row_col);
XAtemp=(float*)malloc((row_col*row_col)*sizeof(float));
for (i=0;i<(row_col*row_col);i++)
fscanf(isa," %f ",&XAtemp[i]);
for (i=0;i<(row_col*row_col);i++)
printf("\n %f \n", XAtemp[i]);
system("pause");
return 0;
is there a way to skip the \n and tell it to continue reading?