scanf format warning for double

前端 未结 4 1462
隐瞒了意图╮
隐瞒了意图╮ 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 16:57

    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 :-)

    0 讨论(0)
  • 2021-01-26 17:01

    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
    0 讨论(0)
  • 2021-01-26 17:09

    Use %lf format specifier for double data type.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题