Hey guys!
I guess my other post wasn't so clear...probably because I wasn't sure what exactly I was trying to do.
Anyway, right now I am having problems reading my input file into my 20x20 2D array. I mean, it compiles fine. But, I have a print function just to see if anything was put into the array, and all I see are 0's.
Below I will post my code and the contents of the input file.
Any help, as always, is appreciated.
This is what is in my input file:
0 0
0 5
0 9
0 19
1 6
1 14
1 16
2 4
2 7
2 11
2 14
2 15
2 16
2 18
3 2
3 5
3 9
3 10
3 17
3 19
4 0
4 3
4 5
4 9
5 2
5 3
5 5
5 15
5 16
5 17
6 5
6 6
6 10
6 11
6 13
6 14
6 17
6 18
7 6
7 8
7 14
7 16
8 1
8 5
8 8
8 10
8 17
9 3
9 4
9 6
9 7
10 0
10 9
10 19
11 1
11 2
11 3
11 5
11 7
11 8
11 14
11 17
11 19
12 4
12 5
12 6
12 8
13 0
13 1
13 7
13 10
13 11
13 14
13 15
13 16
13 17
13 18
14 2
14 11
14 13
14 15
14 17
14 19
15 11
15 13
15 18
16 1
16 2
16 5
16 8
16 17
17 5
17 6
18 6
18 16
18 18
19 0
19 3
19 4
19 7
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
#include <iomanip>
using namespace std;
const int ROW=20;
const int COL=20;
void readLife(int bacteria[][COL]);
void initLife(int bacteria[][COL]);
void printLife(int bacteria[][COL]);
int main()
{
int bacteria[ROW][COL];
readLife(bacteria);
printLife(bacteria);
system("pause");
return 0;
}
//*************************************************************************
void readLife(int bacteria[][COL])
{
ifstream infile; //declare a file variable
int row;
int col;
infile.open("input.dat"); //open a file
assert(infile); //make sure file opened
initLife(bacteria); //initialize 2D array to 0
infile>>row>>col;
while(infile)
{
bacteria[row][col];
infile>>row>>col;
}
infile.close();
}
//***************************************************************************
void initLife(int bacteria[][COL])
{
for(int row=0;row<ROW;row++)
{
for(int col=0;col<COL;col++)
{
bacteria[row][col]=0;
}
}
}
//****************************************************************************
void printLife(int bacteria[][COL])
{
int col;
for(col=0;col<COL;col++)
{
cout<<bacteria[5][col]<<'\n';
}
}