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 *’...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c语言倒序输出字符串数组,【C语言】利用
- 下一篇: 空调c语言入门自学视频教程,本人大一,自