【发布时间】:2015-08-24 11:30:58
【问题描述】:
我收到此错误:
警告:格式“%f”需要类型“float *”,但参数 4 具有类型 'int *'
在这一行:
temp = sscanf(data,"%*c %d %f %f %f",&uptime, &inputs, &systemstatus.adc4, &voltage, &idle);
我不明白为什么会这样,有人可以向我解释一下吗?
我正在使用带有 make 的 GCC 编译器,
#include "main.h"
void processcmd(char *data) {
char foo[300];
int temp, temp2, temp3;
_statusstruct tempstatus;
int uptime;
int inputs;
float voltage;
float idle;
if (data[0] != 'S') { sprintf(foo,"> %s",data); menu_main_log(foo); }
switch (data[0]) {
case 'S':
temp = sscanf(data,"%*c %d %d %f %f %f %f %f %d %d",
&tempstatus.uptime,&tempstatus.inputs, &tempstatus.adc0, &tempstatus.adc1,
&tempstatus.adc2, &tempstatus.adc3, &tempstatus.voltage, &tempstatus.idle,
&tempstatus.debug);
if (tempstatus.uptime < systemstatus.uptime) {
// big trouble: IO card rebooted.
state = STATE_RESET;
systemstatus.uptime = 0;
printf("Detected IO reboot\n");
break;
} else if (temp == 9) {
memcpy(&systemstatus,&tempstatus,((char*)&tempstatus.newdata) - ((char*)&tempstatus));
for (temp = 0; temp < 16; temp++) {
if (systemstatus.inputs & (1<<temp)) buttons[temp][2] = 1;
else buttons[temp][2] = 0;
}
systemstatus.newdata = 1;
} else {
printf("Status line was invalid (%d)\n", temp);
}
break;
case 'I':
temp = sscanf(data,"%*c %d %d", &temp2, &temp3);
if (temp == 2) {
if (temp2 >= 0 && temp2 <= 15 && (temp3 == 0 || temp3 == 1)) {
buttons[temp2][temp3] = 1;
}
buttons[temp2][2] = temp3; // current state
if (temp2 >= 3 && temp2 <= 6 && temp3 == 1) buzzer_on(5000,200);
}
break;
case 'E': // error report. rest of the line is the text
break;
case 'O': // reply on output status set/request
break;
case 'T': // reply on heater setting set/request
break;
case 'C': // reply on calibration command
break;
case 'H': // reply on calibration command
temp = sscanf(data,"%*c %d %f %f %f",&uptime, &inputs, &systemstatus.adc4, &voltage, &idle);
break;
default:
printf("Unknown command: %s\n",data);
break;
}
}
【问题讨论】:
-
voltage的类型是什么? -
该消息应该是不言自明的。它告诉您编译器的预期和实际传递的内容。
-
看来你声明的是
int inputs;而不是float inputs; -
只是我,还是论据4
inputs,而不是voltage? -
寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:如何创建minimal reproducible example。
标签: c