function - 使用 argv 和 argc 向函数发送参数
问题描述
有人可以帮助我了解我需要如何将参数发送到函数“lora_rf_config”吗?非常感谢 !
我尝试:
char cfgred[7][10]={'lora_rf_config','915000000','10','0','1','8','14'};
lora_rf_config(7,&cfgred);
我试图使用的功能是:
static void lora_rf_config(int argc, char *argv[])
{
if (argc == 1) {
e_printf("OK%d,%d,%d,%d,%d,%d\r\n", g_lora_config.lorap2p_param.Frequency,
g_lora_config.lorap2p_param.Spreadfact,
g_lora_config.lorap2p_param.Bandwidth,
g_lora_config.lorap2p_param.Codingrate,
g_lora_config.lorap2p_param.Preamlen,
g_lora_config.lorap2p_param.Powerdbm );
return;
} else {
if (argc != 7) {
out_error(RAK_ARG_ERR);
return;
}
if (!(CHECK_P2P_FREQ(atoi(argv[1])) &&
CHECK_P2P_SF(atoi(argv[2])) &&
CHECK_P2P_BDW(atoi(argv[3])) &&
CHECK_P2P_CR(atoi(argv[4])) &&
CHECK_P2P_PREMLEN(atoi(argv[5])) &&
CHECK_P2P_PWR(atoi(argv[6])))) {
out_error(RAK_ARG_ERR);
return;
}
if (read_partition(PARTITION_0, (char *)&g_lora_config, sizeof(g_lora_config)) < 0) {
out_error(RAK_RD_CFG_ERR);
return;
}
g_lora_config.lorap2p_param.Frequency = atoi(argv[1]);
g_lora_config.lorap2p_param.Spreadfact = atoi(argv[2]);
g_lora_config.lorap2p_param.Bandwidth = atoi(argv[3]);
g_lora_config.lorap2p_param.Codingrate = atoi(argv[4]);
g_lora_config.lorap2p_param.Preamlen = atoi(argv[5]);
g_lora_config.lorap2p_param.Powerdbm = atoi(argv[6]);
write_partition(PARTITION_0, (char *)&g_lora_config, sizeof(g_lora_config));
e_printf("OK\r\n");
}
return;
}
我得到的错误是:
..\..\..\src\application\RAK811\app.c(107): error: #26: too many characters in character constant
char cfgred[7][10]={'lora_rf_config','915000000','10','0','1','8','14'};
我对这种论点没有经验。感谢您的时间。
解决方案
您的初始化未正确完成,请尝试更改
char cfgred[7][10]={'lora_rf_config','915000000','10','0','1','8','14'};
进入
char cfgred[7][16]={"lora_rf_config","915000000","10","0","1","8","14"};
推荐阅读
- android-studio - 带有 Anko 未知资源和空引用的 Kotlin
- java - 通过带有 SSL 的 JDBC 连接到 Google Cloud PostgreSQL
- java - 如何在 Xodus 中获取给定实体类型的属性类型?
- angular - “可观察”类型上不存在属性“uiSignal”
- javascript - 带标题的图片 - vuepress
- android - Unity Google Play 游戏创建游戏有邀请问题
- python - 使用 Python 开源创建有组织的图片库
- python - 用 Python 截取的截图是全黑的
- python - Canvas.Tag_bind 不适用于 OOP | 蟒蛇 3
- excel - 如何计算具有条件的唯一值列表