Reading from a file to map a 2-dimensional array

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:
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
#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:
1
2
3
4
5
6
7
8
9
10
1234567890
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ<>?!
1234567890
ABCDEFGHIJ
KLMNOPQRST
UVWXYZ<>?!
1234567890
ABCDEFGHIJ


(EDIT: Moved from Beginners to Windows Programming, because I didn't get any results in Beginners.)
Last edited on
Topic archived. No new replies allowed.