Hello people,

Quick question. I am working on a mouse maze project, and I need help reading the maze into a dynamically created multi-dimensional array, called "maze". I have already implemented a working code as long as the type of "maze" is char. Below is the code for that:

bool initializeMaze(ifstream& inputFile, char **maze)
{
     int rows = 0, cols = 0; // local variables
     
     inputFile.open("copy.txt");
     if (inputFile)
     {     
         // read row and col size for the array
         inputFile >> rows;
         inputFile >> cols;
         // create a maze of x row's and x col's.
         maze = new char* [rows];
         for (int row = 0; row < rows; row++)
         maze[row] = new char[cols];

         // read the maze into the array
         for (int row = 0; row < rows; row++)
             {
                  cout << endl;
             for (int col = 0; col < cols; col++)
                 {
                      inputFile >> maze[row][col];
                      cout << maze[row][col];
                 }
             }

         
         return true;
     }
     else
     return false;
}

Now, to my question: What if my dynamic array "maze" was an integer array? Please do not respond with liners. A fully working code would be immensely appreciated. Just take my code above and edit to create what I asked.

Also, the format of the input file is:
First two numbers on top are row's and col's. The rest is the maze.

4 4
1111
1100
1111

THANK YOU!

Recommended Answers

All 9 Replies

Just take my code above and edit to create what I asked.

would you like a side of fries with your order..

would you like a side of fries with your order..

"Please do not respond with liners"
You should post the submission procedure so I can just do it for you.

commented: teehee +6

By the way, there is an error in this code which will not be directly visible except to an experienced programmer. But regardless, if someone can just redo the code for me under the assumption that the array is a type int array I will be very happy, as long as the syntax and logic remains intact. This is not a homework project. Please do not think that you are "doing it for me". You are merely helping me.

And yes, I'll take large fries with that.

>> By the way, there is an error in this code which will not be directly visible except to an experienced programmer.

So now you've spotted an error, but won't say what it is? Anyone completing the code has to fix the error too? To say nothing else, I admire the chutzpah.

So do you not know how to do it or do you in fact know how to do it and just your time is too valuable to do it yourself?

>> Please do not think that you are "doing it for me". You are merely helping me.

Then why are we giving you the completed code?


On a side note, whenever I see threads like this, I always wonder whether it's a prank and someone like Niek E. or Salem or Narue or whoever actually wrote it as some sort of gag.

>> By the way, there is an error in this code which will not be directly visible except to an experienced programmer.

So now you've spotted an error, but won't say what it is? Anyone completing the code has to fix the error too? To say nothing else, I admire the chutzpah.

So do you not know how to do it or do you in fact know how to do it and just your time is too valuable to do it yourself?

>> Please do not think that you are "doing it for me". You are merely helping me.

Then why do are we giving you the completed code?


On a side note, whenever I see threads like this, I always wonder whether it's a prank and someone like Niek E. or Salem or Narue or whoever actually wrote it as some sort of gag.

One of the things I enjoy is seeing Narue rip someone a new one. One of the biggest reason I kept coming back. Where is the Code Godess?

>> Please do not think that you are "doing it for me". You are merely helping me.
Not only do you want our code, you also want credit?

I could write the code for you...

or I could explain a simple concept relating char and int types and let you experiment and come up with working code on your own.

What you are asking is quite simple, instead of using 'char' types directly (which are representation from the ascii table) you could store the ascii value of character in an 'int' data type. Example:

char x;
int  y;

y = 82; 
x = y;
 
cout << y << " is the ascii value for " << x;

Given a little bit of knowledge (and not having the complete code done for you) suprise us with some code of your own.

You guys are quite amusing. But seriously, can't you just do what I demanded? haha, just kidding. Well, here is what happened: Just like there is a writer's block, there is also a coder's block, and I was suffering from it earlier. To create the simple code above took me 1.5 hours. My mind is in shambles. Still is. I just want to get this stuff rolling so I can move forward. As for the error, it's an error that whether you are aware of it or not will not matter. And seriously, this isn't a homework. I took a data structures course last semester but was unable to study steadily since I was working full-time in the financial industry. But now that I have some breathing time, I am revisiting the course to grasp the concepts. This is the last request, if no one will help, then I must cease my presence. And you may continue to make sarcastic responses and amusing comments instead of simply helping and getting this over with.

Also, thank you for your help Clinton, but if you can just do the code for me, I'd owe you a big thanks. Trust me, seeing the actual code will be tenfold helpful than me struggling. It will be like an instant-refreshing vision of something I have already done, and that's what I need.

You can't possibly be confused why people are reacting this way.


But what the hell. You amuse me. I'll make you a deal. I'll give you the code. In return, you have to help someone else on the forum with some coding to distinguish yourself from the "Give me teh codez" freeloader types that we see 500 times a day here. Deal?

I know I'll regret this...;)

bool initializeMaze(ifstream& inputFile, int **maze)
{
     const int FREE_SPACE = 0;
     const int WALL = 1;
     char mazeChars[2];
     mazeChars[FREE_SPACE] = ' ';
     mazeChars[WALL] = 'X';

     int rows = 0, cols = 0; // local variables
     
     inputFile.open("copy.txt");
     if (inputFile)
     {     
         // read row and col size for the array
         inputFile >> rows;
         inputFile >> cols;
         // create a maze of x row's and x col's.
         maze = new int* [rows];
         for (int row = 0; row < rows; row++)
         maze[row] = new int[cols];

         // read the maze into the array
         for (int row = 0; row < rows; row++)
             {
                  cout << endl;
             for (int col = 0; col < cols; col++)
                 {
                      inputFile >> maze[row][col];
                      cout << mazeChars[maze[row][col]];
                 }
             }

         
         return true;
     }
     else
     return false;
}

This is one way of at least a dozen of doing this. Whether it works with the rest of your program, who knows, since we can't see it, and like you said, there's at least one serious bug.

Anyway, if this doesn't work for you, you need to clarify your needs and prove to us that you're willing to put in the effort. And if it does work for you, like I said, you should help at least one person on the forum in response.

No, I am far from confused at the reactions. It's pretty standard on every forum, sometimes even I end up acting like these automatons, but mostly I act like you and help people out. Your code shall be put to test and I will respond with the results tomorrow since I must now leave. If it works, I will be more than willing to help a poor soul out, if it doesn't, I shall be back. Thank you humbly, sir.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.