将数组字符串传递到功能指针中



我想我想发送这个全局:

static char content[MAX_NUM_WORDS][MAX_WORD_LEN];

作为函数指针的参数,其中功能指针def:

void(*flashReadDelegate)(char*[])=0;

并用:

来打电话
//save some data in (which prints ok)
strcpy(content[record_desc.record_id],toSave);
// ***Send the delegate out
(*flashReadDelegate)(content);  // ** here there is a compiler warnning about the argument

,如果我想发送content

,指针参数应该如何

void(*flashReadDelegate)(char*[])=0;是错误的。您的功能指针应该像这样

void (*flashReadDelegate)(char (*)[MAX_WORD_LEN]);  

您尚未提及flashReadDelegate指向的功能的原型。我假设它的原型将是

void func(char (*)[MAX_WORD_LEN]);

现在,在函数调用(*flashReadDelegate)(content);中,参数数组content将转换为指针转换为MAX_WORD_LEN char S((*)[MAX_WORD_LEN](的数组。

您对content的声明不是指针。它是max_num_words of max_word_len字符的数组。

如果您想要字符串数组您需要将content声明为:static char* content [max_num_words];`

最新更新