gpt4 book ai didi

c - 自定义函数新手,并且有指针问题

转载 作者:行者123 更新时间:2023-11-30 19:37:05 32 4
gpt4 key购买 nike

所以我有一个非常简单的代码来使用用户的输入来计算声速,当我运行该程序时,我得到一个答案,但它不正确,并且出现错误

'Line 14: assignment makes integer from pointer without cast'.

我不知道这意味着什么,并尝试调整我的指针和函数来尝试解决此问题。任何帮助,将不胜感激。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int SpeedofSound(int t,int Answer);
int t,Answer;
int *pAnswer;

int main(void)
{
printf("Please enter a Temp (Fahrenheit) to calculate the speed of sound.\n");
scanf(" %d", &t);

Answer = SpeedofSound;
printf("At Temp %d, the Speed of sound is %d feet/second.", t, Answer);
return 0;
}

int SpeedofSound(int t,int Answer)
{
*pAnswer = 1086 * sqrt(((5 * t) + 297)/247);
Answer = *pAnswer;
return (Answer);
}

最佳答案

这是你的问题:

Answer = SpeedofSound;

这不是函数调用,而是赋值。将函数的地址分配给名为 Answer 的整型变量。改为这样做:

Answer = SpeedofSound(t);

并重写该函数以采用一个参数。放下 pAnswer 的东西。祝你好运

关于c - 自定义函数新手,并且有指针问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40290794/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com