So I want to make a text-based game that has different maps, displayed in ASCII art-style. I've been tinkering with fstream, and I wrote up this code:
#include <iostream>
using namespace std;
#include <fstream>
int main()
{
ifstream indata;
int i;
int j;
int k;
char grid[9][9];
char letter;
indata.open("grid.txt");
indata >> letter;
while(!indata.eof() )
{
grid[i][j] = letter;
indata >> letter;
i++;
k++;
if(k == 10)
{
k = 0;
j++;
}
}
for(int l; l < 10; l++)
{
cout << endl;
for(int m; m < 10; m++)
cout << grid[l][m];
}
}
It should take the contents of the grid.txt file and map them to the grid array, and then display the grid array. I'm doing this to save me a couple hundred lines of code, because otherwise I would have to change each array element's value for each map. This way I can just write the ASCII map in a .txt file and then add it to an array.
This is where the problem comes in. When I run the program, it says "FileTests.exe has stopped working" (FileTests, of course, being the file name). Does anyone know what I'm doing wrong, or if there is a simpler solution to mapping an array from a file?
PS: I've included the contents of the grid.txt file, simply some characters and numbers to test the potential of this mapping solution:
1234567890
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ<>?!
1234567890
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ<>?!
1234567890
ABCDEFGHIJ