gpt4 book ai didi

c - 我不断收到此错误 : pointer value used where a floating point value was expected

转载 作者:行者123 更新时间:2023-11-30 19:13:59 24 4
gpt4 key购买 nike

我已经看到了一个关于它的问题,不止一个,但它并没有真正解决我的问题。代码比较大,但是问题出在这部分。我有这个东西:

int globalx=12;  
int globaly=10;

void Function (int measurex, int measurey)
float thingx()
{
(((globalx/2)-measurex)/(globalx/2));
}
float totalx=globalx/(float)thingx;
float totaly=globaly/2;

并且有问题会返回该错误。顾名思义,globalx 和 globaly 是两个全局变量。我在这里做错了什么?我怎样才能写出一些东西来实现我在这里想做的事情呢?

最佳答案

关于您的代码的一些事情:

  • thingx 替换为 thingx()
  • Function 定义应位于大括号 {...} 内。
  • Function 定义之外定义 thingx()(依赖于编译器,自 Nested functions are not allowed in standard C 起)。
  • thingx() 函数添加 return 语句。
  • intmeasurex 添加为 thingx() 函数的参数。
  • Function中,获取totalx和totaly的值后,您没有对它们执行任何操作(也许您只是没有将此函数的完整代码放入您的问题中)。

您的函数定义应如下所示:

float thingx(int measurex)
{
return (((globalx/2)-measurex)/(globalx/2));
}

void Function (int measurex, int measurey) {
float totalx=globalx/(float)thingx(measurex); // <-- missing parentheses, should be thingx(...)
float totaly=globaly/2;

// You probably want to do something with totalx and totaly here...
}

主要:

int globalx=12;  
int globaly=10;

Function(globalx, globaly);

此外,请记住,这会将结果截断为整数 globaly/2,因为 globaly 被定义为 int(您可以阅读有关整数除法的内容: What is the behavior of integer division? )

关于c - 我不断收到此错误 : pointer value used where a floating point value was expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34804633/

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