#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
ofstream fileout("stdout.txt", ios::out);
struct Path
{
public:
static const int X = 0;
static const int Y = 1;
int pos[][2];
int curPos;
friend class Matrix;
};
class Matrix
{
public:
Matrix(const char* file);
int dirMove(int posX, int posY);
Path paths[];
int pathnum;
int dimX;
int dimY;
char matrix [100][100];
int initPosX;
int initPosY;
int endPosX;
int endPosY;
int posX;
int posY;
};
Matrix::Matrix(const char* file)
{
fileout << "in constructor" << "\n \n";
ifstream filein;
filein.open(file, ios::in);
bool looping = true;
int posX = 0;
int posY = 0;
bool looped = false;
while(looping)
{
if(filein.eof())
{
looping = false;
}
filein.getline(matrix[posY], 100);
if(!looped)
{
dimX = filein.gcount();
looped = true;
}
posY++;
}
dimX--;
dimY = --posY;
filein.close();
pathnum = 0;
looping = true;
/*bool startfound = false;
bool endfound = false;
posX = 0;
posY = 0;
while(looping)
{
if(matrix[posX][posY] == 's')
{
initPosX = posX;
initPosY = posY;
this->posX = posX;
this->posY = posY;
}
if(matrix[posX][posY] == 'x')
{
endPosX = posX;
endPosY = posY;
}
if(startfound && endfound)
{
looping = false;
}
posX++;
if((matrix[posX][posY] == '\n') || (matrix[posX][posY] == '\r'))
{
posY++;
posX = 0;
}
}*/
}
int Matrix::dirMove(int posX, int posY)
{
}
/*******************************************************************
********************************************************************
*******************************************************************/
int main(int argc, char* argv[])
{
Matrix matrix = Matrix("matrix.txt");
for(int a = 0; a < matrix.dimY; a++)
{
fileout << matrix.matrix[a];
fileout << "\n";
}
fileout << "\n" << matrix.initPosX << " " << matrix.initPosY;
fileout << "\n" << matrix.endPosX << " " << matrix.endPosY;
/*******************************************************************
********************************************************************
*******************************************************************/
/*******************************************************************
********************************************************************
*******************************************************************/
fileout.close();
return 0;
}
run-time error
Okay, I have been put into the classical rat maze challenge by one of my folks, and thus... Okay, this is not in the AI section because I have this wierd run-time problem where nothing is getting executed, basically meaning... Nothing. Absolutely NADA executes (I had little print streams for debugging purposes in there, and they don't run.)
Anyways, here's the code that works:
The huge area that's commented out is the problem code... And I can't find a single thing wrong with it. (And yes, I have just started and am only trying to get the loading done right)
Help?
As far as I can tell your program shouldn't even compile. Things like int pos[][2]; are illegal in classes and structs. What compiler are you using?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement