gpt4 book ai didi

c - C 中的结构顺从

转载 作者:太空宇宙 更新时间:2023-11-04 03:54:34 25 4
gpt4 key购买 nike

struct at_response_code
{
uint8_t *p_string;
uint8_t event_id;
uint8_t message_id;
};


struct at_response_code frc_table[] =
{
(uint8_t*)"OK", EVENT_GSM_ACK_RESPONSE,GSM_MSG_ERROR,
(uint8_t*)"+CMS ERROR:", EVENT_GSM_ERROR_RESPONSE, GSM_MSG_ERROR,
(uint8_t*)"+CME ERROR:", EVENT_GSM_ERROR_RESPONSE,GSM_MSG_ERROR,
(uint8_t*)"ERROR", EVENT_GSM_ERROR_RESPONSE,GSM_MSG_ERROR,
// array terminator !!!
(uint8_t*) 0, 0, 0
};

static uint8_t parse_command(uint8_t* p_data, struct at_response_code *table, uint8_t* message_id)
{
struct at_response_code* p_table;
uint8_t i = 0;
uint8_t j;
p_table = &sms_table[0];
do
{
// j = strlen(&(table->p_string));
j = strlen((char*)&(table[i].p_string));
if((memcmp_P(table[i]->p_string, p_data, j)) == 0)
{
*message_id = table[i]->message_id;
return table[i]->event_id;
}
i++;
}
while(table[i]->p_string != 0);
return 0;
}

在这里,当我尝试使用 strlen 查找结构中定义的字符串的长度时,我总是收到一个错误,如取消引用错误或指向不完整类型的指针的下标......任何人都可以帮助

最佳答案

这是错误的,无论它出现在哪里:

table[i]-> ...

table 是指向结构(或结构数组)的指针。所以 table[i] 是一个 struct 而不是指向 struct 的指针,所以你需要 . 运算符来获取它成员。

编辑

还有一件事,我刚刚注意到你的 frc_table 初始化器是错误的,每个结构体初始化器都需要大括号

struct at_response_code frc_table[] =
{
{ (uint8_t*)"OK", EVENT_GSM_ACK_RESPONSE,GSM_MSG_ERROR },
{ (uint8_t*)"+CMS ERROR:", EVENT_GSM_ERROR_RESPONSE, GSM_MSG_ERROR },
{ (uint8_t*)"+CME ERROR:", EVENT_GSM_ERROR_RESPONSE,GSM_MSG_ERROR },
{ (uint8_t*)"ERROR", EVENT_GSM_ERROR_RESPONSE,GSM_MSG_ERROR },
// array terminator !!!
{ (uint8_t*) 0, 0, 0 }
};

关于c - C 中的结构顺从,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17699723/

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