问题描述
我正在处理的程序有一个小问题,我不断收到警告format '%1f' expects type 'float *' but argument 2 has type 'double *'
,所以我很确定这是我的scanf
格式存在的问题.
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.
此功能读取两个数字.
void read(double *n1, double *d1)
{
printf("Enter the number n1: ");
scanf("%1f", n1);
printf("Enter the number d1: ");
scanf("%1f", d1);
}
推荐答案
将scanf("%lf", n1)
用于double
;请注意"l"(el,而不是一个").如果您不熟悉编程,请尝试熟悉文档,例如 cppreference .例如,您可以在其中找到为scanf
指定的格式和长度矩阵.
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
.
玩得开心,学习编程,使用google等工具,不要犹豫,问:-)
Have fun with learning programming, use google et al, and don't hesitate to ask :-)
这篇关于scanf格式警告为双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!