Jump to content
  • Advertisement
Sign in to follow this  
Atash

run-time error

This topic is 4704 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
#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;
}



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?

Share this post


Link to post
Share on other sites
Advertisement
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!