作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经看到了一个关于它的问题,不止一个,但它并没有真正解决我的问题。代码比较大,但是问题出在这部分。我有这个东西:
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/
我是一名优秀的程序员,十分优秀!