我的代码中有一些问题:
UINT8 PoWerSignal = MyScanResults.signal;
char Signal[8];
sprintf(Signal, "%d", PoWerSignal);
float decibel = 0;
decibel = 10 * log(Signal);
dbgwrite("SIGNAL: ");
_dbgwrite(decibel);有一个错误:
错误:“logf”参数1的不兼容类型
我不知道怎么解决这个问题,也不知道这意味着什么。
发布于 2013-12-13 17:41:40
您正在将一个char数组(在这里称为"string“:Signal,存储在PoWerSignal中的值的字母数字表示)传递给log(),最有可能的不是期望这样的输入,而是一个数字。
您可能希望传递函数log()的数值表示形式如下:
#include <stdio.h> /* To have the prototypes foe the printf family of functions. */
...
UINT8 PoWerSignal = MyScanResults.signal;
char Signal[8] = "";
snprintf(Signal, sizeof(Signal), "%d", PoWerSignal);
float decibel = 10. * log(PoWerSignal);
...另一方面,函数_dbgwrite()似乎需要一个char数组。为此,使用snprintf() out decibel创建一个“字符串”以传递给它,如下所示:
...
char descibel_str[64] = "";
snprintf(decible_str, sizeof(decibel_str), "%f", (double) decibel);
dbgwrite("SIGNAL: ");
_dbgwrite(decibel_str);注意snprintf()而不是sprintf()的用法:这个“转换”函数的前一个版本确实注意到没有溢出目标缓冲区,即存储传递的参数的字母数字表示。这是很容易发生的,而且会引起不明确的行为。
发布于 2013-12-13 17:25:31
看起来你在发送一个坏数据类型(信号)。也许这应该是一个浮点数或无符号的int,而不是字符数组?"char“表示一串文本,您不能将其作为一个数字来操作。
https://stackoverflow.com/questions/20572371
复制相似问题