[今天,我决定回顾一下C编程语言的基础知识,并且在Code :: Blocks IDE中遇到了这个小问题:当我使用%f
格式标识符读写十进制数时,一切顺利,但是当我切换到%lf
格式标识符时,它无法正确读取或写入数字。
这是我的代码:
#include <stdio.h>
int main()
{
double x;
scanf("%lf", &x);
printf("x = %lf", x);
return 0;
}
我已经在线搜索了一个解决方案,包括Code :: Blocks论坛,但是我没有发现任何相关的解决方案。我不确定是编译器问题还是IDE问题。如果您知道修复程序或对此问题有解释,请帮助我。我敢肯定其他人也会遇到此问题。
尚不清楚是什么Code :: Blocks警告。 lf
格式字符串中的scanf
也带有下划线,但绝对正确,因为目标变量的类型为double
。
对该线程有兴趣的人对此问题进行了更详细的描述:Correct format specifier for double in printf