gpt4 book ai didi

c - 将数组字符串传递给函数指针?

转载 作者:行者123 更新时间:2023-12-02 08:13:08 24 4
gpt4 key购买 nike

我猜有些事情根本上是错误的,我想发送这个全局:

static char content[MAX_NUM_WORDS][MAX_WORD_LEN];

作为函数指针的参数,其中函数指针定义:

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 指向的函数的原型(prototype)。我假设它的原型(prototype)是

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

现在,在函数调用 (*flashReadDelegate)(content); 中,参数数组 content 将被转换为指向 MAX_WORD_LEN 数组的指针 chars ((*)[MAX_WORD_LEN]).

关于c - 将数组字符串传递给函数指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44271196/

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