scanf format warning for double

前端 未结 4 1496
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 16:46

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 *\'

4条回答
  •  别那么骄傲
    2021-01-26 17:14

    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.

提交回复
热议问题