sudoku

I am trying to write a program that will help play Sudoku. It needs to read in the data from a txt file using a get. And follow the letter commands N= new game, A= add character, R= remove d= display board. What I am having difficulty with at the moment is reading the board into a 2d array board. After N it should read in the next characters including the blanks into an array. I can't seem to get the right numbers in the right format. The input will be attached below thanks for any help

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  #include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
const int MAXCOL = 9;
const int MAXROW = 9;

void dis_board(char arr[][MAXCOL]);
void new_board(char arr[][MAXCOL], char ch, ifstream& in);
int main()
{
	char board[MAXROW][MAXCOL];
	int row, col, num_ele = 0, num1;
	char ch1;
	ifstream infile;
	infile.open("mp6in.txt");

	infile.get(ch1);
	while (infile)
	{
		
		if (ch1 == 'N')
		infile.ignore(10, '\n');
		infile.get(ch1);


			
		
			new_board(board, ch1, infile);

		//dis_board(board);
		
		infile.get(ch1);
	}
	dis_board(board);
}
void dis_board(char arr[][MAXCOL])
{
	for (int i = 0; i < MAXROW; i++)
	{
		for (int j = 0; j < MAXCOL; j++)
		    cout << arr[i][j] << " ";
		    cout << endl;
    }
}
void new_board(char arr[][MAXCOL],char ch, ifstream& in)
{
	for (int i = 0; i < MAXROW; i++)
	{
		for (int j = 0; j < MAXCOL; j++)
		{
			in >> (arr[i][j]);
		}
	}
}
	



Input file



N
145369287
629785431
783412569
567148392
938527 14
214936758
851 74623
492853 76
376291845
D
R 7 7
A 7 7 9
A 7 4 6
A 8 7 1
A 5 7 6
D
N
6892731
921653847
57314 269
154 6972
689271453
742395 81
257834196
19 762538
365 972
D
A 9 9 4
A 1 1 4
A 8 3 4
A 1 9 5
A 9 1 8
A 4 5 8
A 6 7 6
A 3 6 8
A 4 1 3
A 9 5 1
D
N
2 4 63
421
9 6 42
9 7 6
35 28
7 1 5
59 6 8
857
18 3 5
D
A 3 2 4
A 4 1 7
A 8 8 8
A 5 5 5
A 6 9 2
A 3 7 9
A 5 8 9
A 0 4 9
A 3 0 3
A 9 1 0
D
A 2 8 5
A 5 9 7
D

What is the purpose of line 24? It reads the first character of the new sudoku board so the new_board will start reading from the second character (the 4).
Last edited on
Topic archived. No new replies allowed.