欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

c 调用c语言形参为double,C学生作业,’%f’需要’float *’类型的参数,但参数2的类型为’double *’...

发布时间:2024/10/14 编程问答 84 豆豆
生活随笔 收集整理的这篇文章主要介绍了 c 调用c语言形参为double,C学生作业,’%f’需要’float *’类型的参数,但参数2的类型为’double *’... 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

参见英文答案 >

Why does scanf() need “%lf” for doubles, when printf() is okay with just “%f”?                                    5个

我正在完成一项任务,我收到了这个警告:

C4_4_44.c:173:2: warning: format ‘%f’ expects argument of type ‘float *’,

but argument 2 has type ‘double *’ [-Wformat]

变量在main中声明为:

double carpetCost;

我把这个函数称为:

getData(&length, &width, &discount, &carpetCost);

这是功能:

void getData(int *length, int *width, int *discount, double *carpetCost)

{

// get length and width of room, discount % and carpetCost as input

printf("Length of room (feet)? ");

scanf("%d", length);

printf("Width of room (feet)? ");

scanf("%d", width);

printf("Customer discount (percent)? ");

scanf("%d", discount);

printf("Cost per square foot (xxx.xx)? ");

scanf("%f", carpetCost);

return;

} // end getData

这让我抓狂,因为这本书说你不使用&在

scanf("%f", carpetCost);

从您传递它的函数访问它时,请参考.

我在这里做错了什么想法?

总结

以上是生活随笔为你收集整理的c 调用c语言形参为double,C学生作业,’%f’需要’float *’类型的参数,但参数2的类型为’double *’...的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。