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 *'
So I'm fairly sure it's a problem with my scanf
format.
I've tried looking all over for a solution but can't seem to find one.
This function reads in two numbers.
void read(double *n1, double *d1)
{
printf("Enter the number n1: ");
scanf("%1f", n1);
printf("Enter the number d1: ");
scanf("%1f", d1);
}
Use
scanf("%lf", n1)
fordouble
; 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 forscanf
.Have fun with learning programming, use google et al, and don't hesitate to ask :-)
Use
%lf
format specifier for double data type.You made a typo and then you duplicated it...
Should be written
Note the difference between
l
(lowercase L) and1
(number one).%lf
stands for long float, which is not an actual C type, but a way to distinguishfloat
(%f
) anddouble
(%lf
). Thel
can be used withd
andi
to specifylong int
andu
forlong 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 thelong
integer constant1l
should be written1L
.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