I\'m having a small problem with a program I\'m working on, I keep getting the warning format \'%1f\' expects type \'float *\' but argument 2 has type \'double *\'
Use scanf("%lf", n1)
for double
; Note the "l" (el, not "one").
If you are new to programming, try to get familiar with documentation, e.g. cppreference. There you find, for example, the matrix of format and length specifies for scanf
.
Have fun with learning programming, use google et al, and don't hesitate to ask :-)
Use correct format specifiers for their respective data types
float %f
double %lf
int %d
or %i
unsigned int %u
char %c
char * %s
long int %ld
long long int %lld
Use %lf
format specifier for double data type.
You made a typo and then you duplicated it...
scanf("%1f", n1);
Should be written
scanf("%lf", n1);
Note the difference between l
(lowercase L) and 1
(number one).
%lf
stands for long float, which is not an actual C type, but a way to distinguish float
(%f
) and double
(%lf
). The l
can be used with d
and i
to specify long int
and u
for long unsigned int
.
These characters are difficult to distinguish, especially with fixed pitch fonts used for programming, for this very reason, one should avoid naming a variable l
, ll
etc. and the long
integer constant 1l
should be written 1L
.