[C++] Multidimensional array problem
I'm using fstream in Visual C++ to read a maze from a text file into a multidimensional array and output it to another text file. I keep running into a problem somewhere along the line because the output is missing lines of the maze and gives me a bunch of weird characters.
This is my code for reading in and outputting:
void read(int &x, int &y, char path[100][100])
{
string filein, fileout;
int l;
cout << "Enter filename: ";
cin >> filein;
l=0;
while(filein[l] != '.')
{
fileout += filein[l];
l++;
}
fileout += "_path.txt";
mazein.open(filein.c_str());
mazeout.open(fileout.c_str());
mazein >> x >> y;
for(int a = 0; a <= y; a++)
{
for(int b = 0; b < x; b++)
{
mazein.get(path[b][a]);
}
mazein.get();
}
}
void print(int x, int y, char path[100][100])
{
for(int a = 0; a <= y; a++)
{
for(int b = 0; b < x+1; b++)
{
if(path[b][a] == 'X')
{
path[b][a] = ' ';
}
mazeout << path[b][a];
}
}
}
Any thoughts?
Last edited by Rambo; 12-06-2004 at 05:24 PM..
|