gpt4 book ai didi

c - 警告 : assignment from incompatible pointer type

转载 作者:太空宇宙 更新时间:2023-11-04 07:01:40 25 4
gpt4 key购买 nike

<分区>

编译以下代码时,我收到警告:

warning: assignment from incompatible pointer type
maze->mazeValue = mazeValue;

这是解迷宫的代码。已经尝试过,但无法确定问题所在。如果我将
char mazeValue[BUFFERSIZE][BUFFERSIZE] 更改为 char\*\* mazeValue**,程序会编译但不会执行。 Windows 抛出警报。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#define BUFFERSIZE (1000)
#define MAZE_ENTRANCE '.'


struct maze {
char ** mazeValue;
int startx, starty;
int numrows;
int initdir;
};

void ReadMaze(struct maze * maze);

int main(int argc, char *argv[]) {
struct maze maze;


ReadMaze(&maze);
printf("Thanks");
//PrintStage(&maze);

return EXIT_SUCCESS;
}


/* Creates a maze from a file */

void ReadMaze(struct maze * maze) {
char buffer[BUFFERSIZE];
char mazeValue[BUFFERSIZE][BUFFERSIZE];
//char workingMaze [BUFFERSIZE][BUFFERSIZE];
//char ** map;
int rows = 0, foundentrance = 0, foundexit = 0;
int columns = 0, i = 0;

/* Determine number of rows in maze */


while ( fgets(buffer, BUFFERSIZE, stdin) ){

//puts(buffer);
columns = strlen(buffer);

/*
for(i=0; buffer[i] != '\0'; i++)
{
//printf("Row: %d\n", rows);
//putchar(buffer[i]);
//printf("\n");
mazeValue[rows][i] = buffer[i];
//putchar(mazeValue[rows][i]);
//printf("\n");
}
*/

strcpy(mazeValue[rows], buffer);

for ( i = strlen(mazeValue[rows]) - 1; isspace(mazeValue[rows][i]); --i )
mazeValue[rows][i] = 0;

/* Check for entrance and save the location if it finds */

if ( !foundentrance && rows == 0) {
i = 0;

printf("rows %d\n", rows );
printf("i %d\n", i );

while ( mazeValue[rows][i] != MAZE_ENTRANCE && mazeValue[rows][i++] ){

if ( mazeValue[rows][i] == MAZE_ENTRANCE ) {
maze->startx = i;
maze->starty = rows;
foundentrance = 1;
}
}
}
++rows;
}

maze->mazeValue = mazeValue;
maze->numrows = rows;

printf("maze->startx %d\n", maze->startx);
printf("maze->starty %d\n", maze->starty );

printf("\n");
printf("Stage 1\n");
printf("=======\n");
printf("maze has %d rows and %d columns\n\n", rows, columns);

i=0;
int j;

for(i=0; i<=rows; ++i)
{
for(j=0; j<=columns; ++j){
printf("%c", mazeValue[i][j]);
printf("%c", mazeValue[i][j]);
}
printf("\n");
}

printf("\n");
printf("foundentrance: %d\n", foundentrance);

}

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