Hello. I'm very new to Compuer Science, and I'm taking a class for fun but I recieved a really hard assignment for homework that I was hoping to get a little bit of help on here and there. It's only compter science for beginners, so I hope it isn't that hard. The assignment is making a program that can solve mazes.
My first problem so far is reading the maze file from the txt file I recieved in class.
The file looks like this:
30 30
**************
* ************
* *********
**** ********
The first number in the file is the number of rows that the maze has and the second number is the number of columns. The way I've broken down the task, I need to take this information off of the file into two int variables (row and cols) and one 2D array (maze[30][30])
From what I've learned about reading files, I came up with this:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char data[10000];
int i = 0;
ifstream mazefile;
mazefile.open ("maze1.txt");
if(mazefile.is_open())
{
while(!mazefile.eof())
{
mazefile >> data[i];
i++;
}
}
for(i=0; i<=10000; i++)
{
cout << data[i];
}
return 0;
}
This is about how far I've gotten in working to get this done, and so far, on the screen, I see 3030********************************* and then a bunch of jumbled up characters for the undeclared parts of the 1D array.
I believe I need to use the >> to get the two numbers at the start of the file, but then I need to use the "get" identifier to get the rest of the maze which is made up of asteriks and whitespaces which will be put in the 2D array.
Could someone please help me get on the right track? I've only really read from files on one other assignment and the online information gets a bit too complicated for me.