我知道有类似的问题,但我仍然无法弄清楚,即使我已经阅读了两个小时。
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/