gpt4 book ai didi

c - 将结构矩阵传递给 C 中的函数

转载 作者:行者123 更新时间:2023-11-30 17:42:18 24 4
gpt4 key购买 nike

我知道有类似的问题,但我仍然无法弄清楚,即使我已经阅读了两个小时。

struct box 
{
char letter;
int occupied; //0 false, 1 true.
};

void fill(struct box**, int, int, char*); //ERROR HERE**


int main(int argc, char** argv)
{
int length=atoi(argv[4]),
width=atoi(argv[5]),

char alphabet[26] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct box soup[length][width];
fill(soup, length, width, alphabet); //HERE**
}

void fill(struct box soup[][], int length, int width, char*alphabet) //AND HERE**
{
//omitted
}

这些是我编译时遇到的错误:

warning: passing argument 1 of ‘fill’ from incompatible pointer type [enabled by default]  
fill(soup, length, width, alphabet);
^

note: expected ‘struct box **’ but argument is of type ‘struct box (*)[(sizetype)(width)]’
void fill(struct box **, int, int, char*);
^

error: array type has incomplete element type
void fill(struct box soup[][], int length, int width, char*alphabet)
^

我不明白为什么会失败,而我拥有的其他一些功能(如这个)确实有效:

void wordsToMemory(char**, char*);   //prototype
char* dictionary[Nwords];
wordsToMemory(dictionary, argv[1]); //calling the method
void wordsToMemory(char* dictionary[], char* argv) //function body
{
//omitted
}

最佳答案

这将使其编译:

void fill(struct box** soup, int length, int width, char* alphabet)

void fill(struct box* soup[], int length, int width, char* alphabet)

使用[][]时,您会收到错误,因为没有从struct box*struct box的转换。

关于c - 将结构矩阵传递给 C 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20649181/

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