gpt4 book ai didi

c - 这些错误是什么?

转载 作者:行者123 更新时间:2023-11-30 16:51:48 26 4
gpt4 key购买 nike

These above are the codes.                  
demo_printf("Sampled NodeId %d %lu\n", NodeId,"Sampled SignalSTR %d %lu\n", Signal,"Sampled FirmwareVER %d %lu\n", FirmwareVER,"Sampled battery %f %lu\n", batt,timestamp);
kaa_error_t error = kaa_logging_add_record(
kaa_client_get_context(kaa_client)->log_collector,
log_record, NULL);

以下是错误。我不明白这些错误是什么。到目前为止,C 语言还是个新手...对于我的浮点变量来说,我无法使用 '%' 来执行我的 random() 函数。以下是错误:

/home/pi/try/client/c/src/kaa_demo.c: In function ‘send_temperature’:
/home/pi/try/client/c/src/kaa_demo.c:72:22: error: invalid operands to binary % (have ‘int’ and ‘double’)
float batt = rand() % 5.0;
^
/home/pi/try/client/c/src/kaa_demo.c:73:21: error: invalid operands to binary % (have ‘int’ and ‘double’)
float cel = rand() % 5.0;
^
/home/pi/try/client/c/src/kaa_demo.c:74:20: error: invalid operands to binary % (have ‘int’ and ‘double’)
float wt = rand() % 5.0; // kaa_logging_data_collection_t is the structure defined to contain temperature and time_stamp
^
/home/pi/try/client/c/src/kaa_demo.c:81:12: error: ‘kaa_logging_data_collection_t’ has no member named ‘NodeId’
log_record->NodeId = kaa_string_copy_create("Screws");
^
/home/pi/try/client/c/src/kaa_demo.c:82:15: error: ‘kaa_logging_data_collection_t’ has no member named ‘SignalSTR’
log_record->SignalSTR = Signal;
^
/home/pi/try/client/c/src/kaa_demo.c:83:12: error: ‘kaa_logging_data_collection_t’ has no member named ‘FirmwareVER’
log_record->FirmwareVER = kaa_string_copy_create("Linux KIDS");
^
/home/pi/try/client/c/src/kaa_demo.c:84:12: error: ‘kaa_logging_data_collection_t’ has no member named ‘OnlineStat’
log_record->OnlineStat = status;

最佳答案

您的前三个错误是由于模数运算符不适用于实数而引起的。您正在使用实数来除以 rand() 的输出(整数)。该主题的解释如下:(Why does modulus division (%) only work with integers?)

您能否分享结构(kaa_logging_data_collection_t)元素:如果可以的话。那么只有任何人都可以确定为什么这些错误会出现在这里。

关于c - 这些错误是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41582847/

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