我正在使用输入重定向解决C程序中的迷宫问题。我对C语言不太熟悉,需要在下面的代码中输入一些内容,我无法正确读取文件。你能否指出错误,以便我可以继续前进。感谢。
#include <stdio.h>
#include <stdlib.h>
#define MAZESIZE (1000)
struct maze {
char ** map;
int startx, starty;
int numrows;
int initdir;
};
void ReadMaze(char * filename, struct maze * maze);
int main(int argc, char *argv[]) {
struct maze maze;
if ( argc < 2 ) {
puts("Please specify the filename of your maze");
return EXIT_FAILURE;
}
else if ( argc > 2 ) {
puts("Too many input files");
return EXIT_FAILURE;
}
ReadMaze(argv[1], &maze);
return EXIT_SUCCESS;
}
void ReadMaze(char * filename, struct maze * maze) {
char buffer[MAZESIZE];
char ** map;
int n = 0, foundentrance = 0, foundexit = 0;
while ( fgets(buffer, MAZESIZE, stdin) )
{
printf("No of rows inside: %d", n);
++n;
}
printf("No of rows: %d", n);
}