2D array copying last int twice

Okay, I am running into a problem with copying integers into a 2D array. I am making a sudoku table with 0's in the empty slots to set it up, then am taking a .txt file with two indices and a value (ie: 0 1 5) would put 5 in the 1 slot of the 0 row, the problem is that whenever I encounter a (X 0 A) it overwrites the (X-1 8 B) slot so it is (X-1 8 A).

I'm sure it's something absolutely stupid and obvious I'm missing.

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
class sudoku {
public:
  sudoku();
private:
  int Grid[8][8];
};



sudoku::sudoku()
{
  int i, j;

  for (i = 0; i < 9; i++){
     for(j = 0; j < 9; j++){
       Grid[i][j] = '0';
     }
  }
 
  std::ifstream infile("game1.txt");  // construct object and open file
  std::string line;

  if (!infile) { std::cerr << "Error opening file!\n"; exit(1); }


   while (std::getline(infile, line)){
     std::istringstream iss(line);
     int c, r, v;
     iss >> r >> c >> v;
   std::cout << "We obtained three values [" << r << ", " << c << ", " << v << "].\n";

   Grid[r][c] = v;

   }

   for(i=0; i <9; i++){
     for(j =0; j<9; j++){
       cout << Grid[i][j];
     }
   }
}
Last edited on
1
2
3
4
5
6
class sudoku {
public:
  sudoku();
private:
  int Grid[8][8]; //// This should be int Grid[9][9];
};
hahahhahahahahah, Thanks buddy, I knew it would be something simple I was overlooking!
Topic archived. No new replies allowed.