I have a matrix G
in MATLAB that I have printed into a text file using:
file = fopen('G.dat','w');
fprintf(file, [repmat('%f\t', 1, size(G, 2)) '\n'], G');
fclose(file);
The dimension of this matrix is 100 x 500. If I count rows and columns using awk, for instance, using
cat G.dat | awk '{print NF}END{print NR}'
I see that the dimensions correspond to the original one.
Now, I want to read this file, G.dat, from a C program that counts the columns of the first row just to understand the columns' dimension as in:
while (!feof(file) && (fscanf(file, "%lf%c", &k, &c) == 2) ) {
Ng++;
if (c == '\n')
break;
}
Unfortunately it gives me Ng = 50000 and it doesn't recognize any of the '\n'. Instead, if I create the text file just by copying and pasting the data, it works. Can you explain me why? Thanks!