This is the code which read a matrix 10x10 from a file "F1.txt"
#include <stdio.h>
int main( int argc, char ** argv ) {
FILE * fr;
fr = fopen("F1.txt","r");
int i, j;
int matrix[10][10] = {0.0};
for(i = 0; i < 10; i++)
{
for(j = 0; j < 10; j++)
{
fscanf(fr, "%d",&matrix[i][j]);
printf("%d\n", matrix[i][j]);
}
}
getchar();
return 0;
}
"F1.txt" looks like this:
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 4 34 56 43 32 124 52 212 3
32 343 34 544 43 32 7 52 456 98
It works without problems but the output is:
12
343
34
544
43
32
124
52
212
3
12
343
34
544
43
32
124
52
212
..........
etc....
I have to detect the end of line to make my input the same like in F1.txt
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 343 34 544 43 32 124 52 212 3
12 4 34 56 43 32 124 52 212 3
32 343 34 544 43 32 7 52 456 98
.