Aşağıdaki kodu dev c++'da projeyi açarken c++ seçip çalıştırınca gayet güzel çalışıyor ancak c seçince çalışmıyor. Bana lazım olan c dilinde çalışması hatam nerede acaba yardımcı olabilirmisiniz.
#include <stdio.h>
const int MazeHeight = 70;
const int MazeWidth = 20;
char Maze[MazeHeight][MazeWidth + 1];
void read()
{
FILE *pf;
int row, column;
char c;
pf = fopen( "lab.txt", "r");
for( row = 0, column = 0;
{
c = fgetc( pf);
if( feof( pf))
{
Maze[row][column] = 0;
break;
}
Maze[row][column] = c;
column++;
if( c == ' ')
{
row++;
column = 0;
}
}
fclose( pf);
}
const char Wall = '#';
const char Free = ' ';
const char SomeDude = '+';
class COORD
{
public:
int X;
int Y;
COORD(int x = 0, int y = 0) { X = x, Y = y; }
COORD(const COORD &coord) { X = coord.X; Y = coord.Y; }
};
COORD StartingPoint(1, 1);
COORD EndingPoint(7, 8);
void PrintDaMaze()
{
for (int Y = 0; Y < MazeHeight; Y++)
{
printf("%s\n", Maze[Y]);
}
printf("\n");
}
bool Solve(int X, int Y)
{
Maze[Y][X] = SomeDude;
if (X == EndingPoint.X && Y == EndingPoint.Y)
{
return true;
}
if (X > 0 && Maze[Y][X - 1] == Free && Solve(X - 1, Y))
{
return true;
}
if (X < MazeWidth && Maze[Y][X + 1] == Free && Solve(X + 1, Y))
{
return true;
}
if (Y > 0 && Maze[Y - 1][X] == Free && Solve(X, Y - 1))
{
return true;
}
if (Y < MazeHeight && Maze[Y + 1][X] == Free && Solve(X, Y + 1))
{
return true;
}
Maze[Y][X] = Free;
return false;
}
int main()
{
read();
if (Solve(StartingPoint.X, StartingPoint.Y))
{
PrintDaMaze();
}
else
{
printf("Damn\n");
}
return 0;
}
lab.txt dosyasındaki labirentde bu;
# ####### # # # # ### # # # # # # # # # ### # # # # # ### # # # - Pastebin.com
#include <stdio.h>
const int MazeHeight = 70;
const int MazeWidth = 20;
char Maze[MazeHeight][MazeWidth + 1];
void read()
{
FILE *pf;
int row, column;
char c;
pf = fopen( "lab.txt", "r");
for( row = 0, column = 0;
{
c = fgetc( pf);
if( feof( pf))
{
Maze[row][column] = 0;
break;
}
Maze[row][column] = c;
column++;
if( c == ' ')
{
row++;
column = 0;
}
}
fclose( pf);
}
const char Wall = '#';
const char Free = ' ';
const char SomeDude = '+';
class COORD
{
public:
int X;
int Y;
COORD(int x = 0, int y = 0) { X = x, Y = y; }
COORD(const COORD &coord) { X = coord.X; Y = coord.Y; }
};
COORD StartingPoint(1, 1);
COORD EndingPoint(7, 8);
void PrintDaMaze()
{
for (int Y = 0; Y < MazeHeight; Y++)
{
printf("%s\n", Maze[Y]);
}
printf("\n");
}
bool Solve(int X, int Y)
{
Maze[Y][X] = SomeDude;
if (X == EndingPoint.X && Y == EndingPoint.Y)
{
return true;
}
if (X > 0 && Maze[Y][X - 1] == Free && Solve(X - 1, Y))
{
return true;
}
if (X < MazeWidth && Maze[Y][X + 1] == Free && Solve(X + 1, Y))
{
return true;
}
if (Y > 0 && Maze[Y - 1][X] == Free && Solve(X, Y - 1))
{
return true;
}
if (Y < MazeHeight && Maze[Y + 1][X] == Free && Solve(X, Y + 1))
{
return true;
}
Maze[Y][X] = Free;
return false;
}
int main()
{
read();
if (Solve(StartingPoint.X, StartingPoint.Y))
{
PrintDaMaze();
}
else
{
printf("Damn\n");
}
return 0;
}
lab.txt dosyasındaki labirentde bu;
# ####### # # # # ### # # # # # # # # # ### # # # # # ### # # # - Pastebin.com