Reputation: 273
I have the following code:
FILE *fp;
double Data[9][7];
int i=0,k;
fp = fopen ( "dstest 2.mod", "r" ) ;
fscanf(fp, "%E %E %E %E %E %E %E*[ ]",
&Data[i][0],
&Data[i][1],
&Data[i][2],
&Data[i][3],
&Data[i][4],
&Data[i][5],
&Data[i][6] );
But whenever I run it I get the following warnings:
Read.c:12: warning: format ‘%E’ expects type ‘float *’, but argument 3 has type ‘double *’
And it goes for all the arguments (Data[i][j]). I have no idea what's wrong. The problem goes away when I use float Data instead of double data. But that will not fit in my requirements.
Upvotes: 0
Views: 277
Reputation: 126867
%E
works with float
s; for double
s you have to use %lE
.
Sadly, inconsistency between the printf
and the scanf
here is not helping (printf
does not support float
s since all variadic arguments of type float
are implicitly converted to double
, but scanf
does make a difference between the two FP types)
Upvotes: 0
Reputation: 36049
man scanf says that you need the l
modifier character to read a double:
fscanf(fp, "%lE %lE...
and so on.
Upvotes: 2