studentCJ (1)
Hi
I am doing the RECURSIVELY FINDING PATHS THROUGH A MAZE project but I got a problem here.
I try to read a file to a 2D char array but it did not work
this is what I have
I tried to print maze[20][20] and the whole maze but the output like this
20|20|||
蘾||
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + + ?Press any key to continue . . .
I believe the unknown character 蘾 represent nothing to be stored in the maze[20][20]. can you help me with this? I cannot find a way to store the space from the file in a char array. Also, I don't know why there is a ? mark before Press any key to continue. Thank you for your help! I am using the VS 2013 on the Windows system.
The file :
20 20
+ ++++++++++++++++++
+ + ++ +++
+++ ++++++ ++ ++
+ +++ +++ ++++
+ + ++ ++++++ +
+++ ++ ++ ++ +
+ +++ ++++ ++ ++ +
+ ++++ ++ +++++ +
+ + +++ +++ +
+ ++ + +++ ++++++ ++
+ +++++ +++ ++
+ +++ ++++ ++ ++
+ ++++ +++ +
+++ +++++++++++ +
++ +++++++ +
++ +++ ++++++++ +
++ ++++++ + +
+ +++ ++++++ +++
++++ +++ +++
+++++++++++++ ++++++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main()
{
int count,i,j,m,l;
char data[1672];
int size[2];
char maze[100][100];
ifstream inputfile;
inputfile.open("maze.dat");
count = 0;
l = 0;
while (l!=2)
{
inputfile >> size[l];
l++;
}
cout << size[0] << "|" << size[1] << "|||"<<endl;
int c=0;
while (!inputfile.eof())
{
for (i = 0; i < size[0]; i++)
{
for (j = 0; j < size[1]; j++)
inputfile >> maze[i][j];
}
}
cout << maze[20][20] << "|||"<<endl;
for (i = 0; i < size[0]; i++)
{
for (j = 0; j < size[1]; j++)
{
cout << maze[i][j] << " ";
}
cout << '\n';
}
system("pause");
return 0;
}
|