双scanf函数不读 [英] Scanf not reading in double
本文介绍了双scanf函数不读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用在双击
值连续读取从用户 scanf函数
。
code:
的printf(输入一个值:\\ n);
双输入;
INT结果= scanf函数(%F,&安培;输入);
的printf(输入:%F \\ N,输入);
的输出是
输入:0.000
解决方案
您谎称编译:扫描时,%F
说你提供一个指向浮动
。但是,你提供了一个指向双击
。
要解决,要么使用%LF
或声明输入
为浮动
。
请注意,有与的printf
格式不对称,它使用%F
为浮动
和双击
参数。这工作,因为的printf
参数都提升到双击
(而不是指针)。
I am trying to read in a double
value continuously from the user using scanf
.
Code:
printf("Enter A value: \n");
double input;
int result = scanf("%f", &input);
printf("INPUT: %f\n", input);
The output is
INPUT: 0.000
解决方案
You lied to the compiler: when scanning, %f
says you supply a pointer to float
. But you provided a pointer to double
.
To fix, either use %lf
or declare input
as float
.
Note that there is an asymmetry with printf
formats, which uses %f
for both float
and double
arguments. This works because printf
arguments are promoted to double
(and are not pointers).
这篇关于双scanf函数不读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文