hat*_*dac 8 c string 2d function
我正在尝试将带有字符串的2D数组传递给函数.我在令牌之前一直得到预期的表达式.
这段代码的重点是阅读wordsearch拼图,然后找到拼图中的单词.我将编写一个函数用于前向搜索,后向搜索,然后上下搜索.
我该如何摆脱这个错误?错误在我称之为前向功能的最底部.
/*Andrea Hatfield CPE 101 October 31st, 2012*/
#include <stdio.h>
#include <string.h>
int forward(char words[][8], char puzzle[][11]);
int main()
{
char puzzle[11][11];
char words[8][8];
FILE *fin, *fwords;
int i = 0;
int j= 0;
fin = fopen("puzzle.in", "r");
fwords = fopen("words.in", "r");
if(fin == NULL) /*Reads in the puzzle file*/
printf("File does not exist");
else
{
while(fscanf(fin,"%s", puzzle[i])!=EOF)
{
printf("%s\n", puzzle[i]);
i++;
}
}
if(fwords == NULL) /*Reads in the words the puzzle will search for */
printf("File does not exist");
else
{
while(fscanf(fwords, "%s", words[j])!=EOF)
{
printf("%s\n", words[j]);
}
}
forward(&words[][8], &puzzle[][11]); /*Error at this point*/
return(0);
}
Run Code Online (Sandbox Code Playgroud)
得到你想要的东西有点难,但这里有一个问题:
forward(&words[][8], &puzzle[][11]);
Run Code Online (Sandbox Code Playgroud)
试试这个:
forward(words, puzzle);
Run Code Online (Sandbox Code Playgroud)
以下是另外两个应该从这里提到的选项:
#define ROWS 4
#define COLS 5
void func(int array[ROWS][COLS]) {
int i, j;
for (i=0; i<ROWS; i++) {
for (j=0; j<COLS; j++) {
array[i][j] = i*j;
}
}
}
void func_vla(int rows, int cols, int array[rows][cols]) {
int i, j;
for (i=0; i<rows; i++) {
for (j=0; j<cols; j++) {
array[i][j] = i*j;
}
}
}
int main() {
int x[ROWS][COLS];
func(x);
func_vla(ROWS, COLS, x);
}
Run Code Online (Sandbox Code Playgroud)